Android drag and drop using DraggableLinearLayout
Android drag and drop using DraggableLinearLayout
MainActivity.java
import android.support.v7.app.AppCompatActivity;import android.os.Bundle;
import android.view.View;
import com.jmedeisis.draglinearlayout.DragLinearLayout;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DragLinearLayout dragLinearLayout = (DragLinearLayout) findViewById(R.id.container);
// set all children draggable except the first (the header)
for(int i = 0; i < dragLinearLayout.getChildCount(); i++){
View child = dragLinearLayout.getChildAt(i);
dragLinearLayout.setViewDraggable(child, child); // the child is its own drag handle
}
}
}
activity_main.xml
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Please Drag and Drop Me Somewhere"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/TextViewStyle" />
<TextView
android:background="@android:color/holo_red_light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/TextViewStyle" />
<TextView
android:text="This tutorial uses a third party library to drag LinearLayouts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/TextViewStyle" />
<ImageView
android:layout_width="match_parent"
android:layout_height="120dp"
android:scaleType="centerCrop"
android:src="@drawable/img_1"
/>
<TextView
android:text="Ever thought how dragging songs in an application playlist works!"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/TextViewStyle" />
</com.jmedeisis.draglinearlayout.DragLinearLayout>
Comments
Post a Comment