ExpandableHeightListView

Additional

Language
Java
Version
N/A
Created
May 23, 2015
Updated
Feb 15, 2017 (Retired)
Owner
Paolo Rotolo (paolorotolo)
Contributor
Paolo Rotolo (paolorotolo)
1
Activity
Badge
Generate
Download
Source code

Advertisement

ExpandableHeightListView

Android Library to put a ListView inside a ScrollView without collapsing.

How to use

Add this to your build.gradle:

repositories {
    mavenCentral()
}

dependencies {
  compile 'com.github.paolorotolo:expandableheightlistview:1.0.0'
}

Add ExpandableHeightListView instead of ListView in your xml files:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <com.github.paolorotolo.expandableheightlistview.ExpandableHeightListView
            android:id="@+id/expandable_listview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="8dp">
        </com.github.paolorotolo.expandableheightlistview.ExpandableHeightListView>
</ScrollView>

Expand ExpandableHeightListView programmatically:

    ExpandableHeightListView expandableListView = (ExpandableHeightListView) findViewById(R.id.expandable_listview);
    
    expandableListView.setAdapter(adapterName);

    // This actually does the magic
    expandableListView.setExpanded(true);

It also works well with GridView.

Just use this instead:

<com.github.paolorotolo.expandableheightlistview.ExpandableHeightGridView
            android:id="@+id/expandable_listview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="8dp">
        </com.github.paolorotolo.expandableheightlistview.ExpandableHeightGridView>

Example

See it in action: download test .apk here.

Also check the example app's sources here on GitHub (ExpandableHeightListViewExample).

##Wait, what? Well, did you ever try to put a ListView inside a ScrollView?

This is what happens.

And this is what you can do with ExpandableHeightListView.

Inspired by this answer on StackOverflow.