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

<com.jmedeisis.draglinearlayout.DragLinearLayout
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>

I Am Not The Owner Of These Code .I Merely Have Copied Them From Various Sources. The Only Thing I Did Is That I Am Going To Present Them In More Easy Way To Understand.

Comments

Popular posts from this blog

LED Blinking using 8051 Microcontroller and Keil C – AT89C51

Android Camera Example 2

Java Script to make text change text color