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/