Search code examples
androidandroid-cardviewexpandablerecyclerview

How to get such an expandable layout?


Does anyone know how to get an expandable layout like the payment method and the in the link? I don't want it to be in a listview because I need such an expandable layout works for other things with different content. Or it could be in an expandable list view if items have different content can be fitted in. Thank you in advance!

http://chairnerd.seatgeek.com/images/autocomplete_checkout.gif


Solution

  • I found a solution.

    Put something like the following in your layout file

    <com.github.aakira.expandablelayout.ExpandableRelativeLayout
                android:id="@+id/expandableLayout4"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/expandableButton4"
                android:background="#ffcc80"
                android:padding="16dp"
                app:ael_duration="400"
                app:ael_expanded="false"
                app:ael_interpolator="accelerate"
                app:ael_orientation="vertical">
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="#FFFFFF"
                    android:text="Things to put in the expandable layout" />
            </com.github.aakira.expandablelayout.ExpandableRelativeLayout>
    

    Add to your build gradle file

    dependencies {
    compile 'com.github.aakira:expandable-layout:1.6.0@aar'}
    

    The way to set onClick listener for expanding the layout

    public void expandableButton1(View view) {
        expandableLayout1 = (ExpandableRelativeLayout) findViewById(R.id.expandableLayout1);
        expandableLayout1.toggle(); // toggle expand and collapse
    }
    

    More detail description: http://www.codeisall.com/android-expandable-layout/