An android layout to re-arrange child views via dragging

Overview

Android Rearrangeable Layout

An android layout to re-arrange child views via dragging

Android Arsenal

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)
You might also like...
Android layout that simulates physics using JBox2D
Android layout that simulates physics using JBox2D

PhysicsLayout Android layout that simulates physics using JBox2D. Simply add views, enable physics, and watch them fall! See it in action with the sam

An Android demo of a foldable layout implementation. Engineered by Vincent Brison.
An Android demo of a foldable layout implementation. Engineered by Vincent Brison.

Foldable Layout This code is a showcase of a foldable animation I created for Worldline. The code is fully written with java APIs from the Android SDK

A 3D Layout for Android,When you use it warp other view,it can became a 3D view,一秒让你的view拥有3D效果!
A 3D Layout for Android,When you use it warp other view,it can became a 3D view,一秒让你的view拥有3D效果!

ThreeDLayout A 3D Layout,When you use it warp other view,it can became a 3D view 中文文档 preview USAGE 1.compile library allprojects { repositories {

It's an Android library that allows you to use Layout as RadioButton or CheckBox.
It's an Android library that allows you to use Layout as RadioButton or CheckBox.

Android - CompoundLayout It's an Android library that allows you to use Layout as RadioButton or CheckBox. The librarie is Android 14+ compatible. Gra

Easy, flexible and powerful Swipe Layout for Android
Easy, flexible and powerful Swipe Layout for Android

SwipeRevealLayout A layout that you can swipe/slide to show another layout. Demo Overview Drag mode Drag mode normal: Drag mode same_level: Features F

Scalable Layout For Android
Scalable Layout For Android

ScalableLayout for Android. Class: com.ssomai.android.scalablelayout.ScalableLayout 한글버전 README.md: https://github.com/ssomai/ScalableLayout/blob/mast

Android implementation of FlowLayout. Layout arranges its children in multiple rows depending on their width.
Android implementation of FlowLayout. Layout arranges its children in multiple rows depending on their width.

FlowLayout FlowLayout is an opensource Android library that alows developers to easily integrate flow layout into their app. FlowLayout is an layout t

Circular layout for android
Circular layout for android

CircleLayout Circular layout for android. Installlation Add CircleLayout as Android Library to your project. How to add project as Android Library Usa

An Android layout for arranging children along a circle
An Android layout for arranging children along a circle

CircleLayout An Android layout for arranging children along a circle You can customize the following options: cl_centerView: Set a specific view ID to

Comments
  • Dynamic Items Issue

    Dynamic Items Issue

    Hello rajasharan

    I saw this useful component and i want to use in my project. In my case i want to add dynamic items, and i get an error.

    This is my code:

    public void addDynamicItemsToTableLayout () { if (null == root) { root = (RearrangeableLayout) findViewById(R.id.rearrangeable_layout); }

        if (null == root)
        {
            Log.d(TAG, "RearrangeableLayout root is NULL");
            return;
        }
    
        ImageView imgView = new ImageView(this);
        imgView.setImageDrawable(getResources().getDrawable(R.drawable.ic_menu_send));
        imgView.setLayoutParams(new Toolbar.LayoutParams(Toolbar.LayoutParams.WRAP_CONTENT, Toolbar.LayoutParams.WRAP_CONTENT));
        
        
        //---------------------------
        //-- Setting the position
        //---------------------------
        imgView.setX(200);
        imgView.setY(300);
    
        root.addView(imgView);
    }
    

    After executing that function i get the following error:

    4-02 10:15:07.209 21223-21223/com.wci.cashregister E/AndroidRuntime: FATAL EXCEPTION: main java.lang.ClassCastException: android.support.v7.widget.Toolbar$LayoutParams cannot be cast to com.wci.rearrangablelayout.RearrangeableLayout$LayoutParams at com.wci.rearrangablelayout.RearrangeableLayout.onMeasure(RearrangeableLayout.java:125) at android.view.View.measure(View.java:16195) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945) at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:714) at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:786) at android.view.View.measure(View.java:16195) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945) at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139) at android.view.View.measure(View.java:16195) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410) at android.widget.LinearLayout.measureVertical(LinearLayout.java:695) at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) at android.view.View.measure(View.java:16195) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945) at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) at android.view.View.measure(View.java:16195) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410) at android.widget.LinearLayout.measureVertical(LinearLayout.java:695) at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) at android.view.View.measure(View.java:16195) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4945) at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2472) at android.view.View.measure(View.java:16195) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2173) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1321) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1532) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1218) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4975) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791) at android.view.Choreographer.doCallbacks(Choreographer.java:591) at android.view.Choreographer.doFrame(Choreographer.java:561) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777) at android.os.Handler.handleCallback(Handler.java:725) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:176) at android.app.ActivityThread.main(ActivityThread.java:5279) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) at dalvik.system.NativeStart.main(Native Method)

    But then i changed Toolbar.LayoutParams to RearrangeableLayout.LayoutParams, but function signature are different, so compilation fails.

    What could be causing this problem? I would appreciate your help.

    Best Regards, Carlos Mejia

    opened by carlosmejia85 4
  • Saving layout before closing to external file not working

    Saving layout before closing to external file not working

    I have tried four different ways to save the layout before it ends so that I can get the saved file or data to reload again. I need help.

    Here is a link to my git: https://github.com/PragramingFleur/TableReservationSystem/tree/tablet-test

    opened by PragramingFleur 0
Releases(v0.1-alpha)
Owner
Raja Sharan Mamidala
Raja Sharan Mamidala
GoolgePlusLayout is a custom layout that plays animation on the children views while scrolling as the layout in the Google Plus (android) main page

Google Plus Layout Google Plus Layout is a custom layout that support playing animation on child view(s) in a serialize manner like the the main

Ahmed Nammari 224 Nov 25, 2022
A pull to refresh layout for android, the RecyclerRefreshLayout is based on the SwipeRefreshLayout. support all the views, highly customizable, code simplicity, etc. really a practical RefreshLayout!

RecyclerRefreshLayout English | 中文版 RecyclerRefreshLayout based on the {@link android.support.v4.widget.SwipeRefreshLayout} The RecyclerRefreshLayout

dinus_developer 1.7k Nov 10, 2022
[UNMAINTAINED]: AndroidMosaicLayout is android layout to display group of views as grid consists of different asymmetric patterns (90 different patterns).

AndroidMosaicLayout AndroidMosaicLayout is android layout to display group of views in more that 90 different patterns. What is AndroidMosaicLayout? I

Adham Enaya 474 Nov 12, 2022
A layout to transition between two views using a Floating Action Button as shown in many Material Design concepts

⚠ This library is no longer maintained ⚠️ FABRevealLayout A layout to transition between two views using a Floating Action Button as shown in many Mat

Tomás Ruiz-López 901 Dec 9, 2022
Responsive Layout Gird Configuration using Compose. An adaptive layout

ResponsiveGrid Responsive Grid is most followed layout system by the designer as it adapts to screen size and orientation, ensuring consistency across

null 4 Apr 12, 2022
Ultra Pull to Refresh for Android. Support all the views.

Welcome to follow me on GitHub or Twitter GitHub: https://github.com/liaohuqiu Twitter: https://twitter.com/liaohuqiu 中文版文档 Wanna auto-load-more? This

Huqiu Liao 9.6k Jan 5, 2023
VoronoiView is a view (ViewGroup) that allows you to add and display views inside Voronoi diagram regions.

Vorolay VoronoiView is a view (ViewGroup) that allows you to add and display views inside Voronoi diagram regions. [Voronoi diagram] (https://en.wikip

Daniil Jurjev 918 Dec 4, 2022
An Android Layout which has a same function like https://github.com/romaonthego/RESideMenu

ResideLayout An Android Layout which has a same function like https://github.com/romaonthego/RESideMenu. Can be used on Android 1.6(I haven't try it.)

Yang Hui 392 Oct 12, 2022
A very simple arc layout library for Android

ArcLayout A very simple arc layout library for Android. Try out the sample application on the Play Store. Usage (For a working implementation of this

ogaclejapan 1.4k Dec 26, 2022