Android Rearrangeable Layout

Additional

Language
Java
Version
v0.1-alpha (Jun 28, 2015)
Created
Jun 21, 2015
Updated
Jul 1, 2015 (Retired)
Owner
Raja Sharan Mamidala (rajasharan)
Contributor
Raja Sharan Mamidala (rajasharan)
1
Activity
Badge
Generate
Download
Source code
APK file

Commercial

Android Rearrangeable Layout

An android layout to re-arrange child views via dragging

Screencast Demo

Layout Usage

All the child views are draggable once the layout is added to an activity (activity_main.xml)

<com.rajasharan.layout.RearrangeableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rearrangeable_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    app:outlineWidth="2dp"
    app:outlineColor="@color/cyan"
    app:selectionAlpha="0.5"
    app:selectionZoom="1.2"
    >

    <!-- add child views with `android:id` attr to
         save position during orientation change -->

    <TextView
        android:id="@+id/textview_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sample Demo with very large text that will overflow in width"
        android:textSize="30sp"
        android:background="@android:color/holo_green_light"
        android:layout_margin="15dp"
        />

    <!-- more child views -->

</com.rajasharan.layout.RearrangeableLayout>

Child Position Listener

Add a ChildPositionListener to the root layout to receive updates whenever any child view is dragged (MainActivity.java)

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    root = (RearrangeableLayout) findViewById(R.id.rearrangeable_layout);
    root.setChildPositionListener(new RearrangeableLayout.ChildPositionListener() {
        @Override
        public void onChildMoved(View childView, Rect oldPosition, Rect newPosition) {
            Log.d(TAG, childView.toString());
            Log.d(TAG, oldPosition.toString() + " -> " + newPosition.toString());
        }
    });
}

License

The MIT License (MIT)