ExpandableLayout

An Android layout class that supports animating the expansion and collapse of its child views.

I built this because all of the available libraries I tested were missing features or behaving unexpectedly in certain cases (e.g. rotation handling).

This library offloads as much work as possible to the parent layout to ensure that the rendering and size calculations behave as expected. This means that even complex features such as LinearLayout's weight tag are properly supported.

Try the demo

Google Play Store badge

Features

ExpandableLayout supports animating:

  • Views with fixed and variable heights:

simple

  • "Accordion" expansion (using two expandable layouts)

accordion

  • RecyclerView items

recycler

  • Horizontal expansion

horizontal

Usage

Reference the library from your module's build.gradle:

dependencies {
    [...]
    compile 'net.cachapa.expandablelayout:expandablelayout:[latest_version]'
}

Latest version: Download

Add ExpandableLayout as a container to the layout or views you want to make expandable:

<net.cachapa.expandablelayout.ExpandableLayout
    android:id="@+id/expandable_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:el_duration="1000"
    app:el_expanded="true"
    app:el_parallax="0.5">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp"
        android:text="Fixed height" />

</net.cachapa.expandablelayout.ExpandableLayout>

Also supported are el_duration and el_expanded tags, for specifying the duration of the animation and whether the layout should start expanded, respectively. el_parallax can be set to a value between 0 and 1 to control how the child view is translated during the expansion.

To trigger the animation, simply grab a reference to the ExpandableLayout from your Java code and and call either of expand(), collapse() or toggle().

A full demo of the library is included with the project.

GitHub