• Stars
    star
    205
  • Rank 190,715 (Top 4 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Expandable Height ListView for Android

ExpandableHeightListView

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

Maven Central Android Arsenal

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.