here is the code am using to display
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/llheadings">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ExpandableListView
android:id="@+id/myExpanded"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/llheadings"
android:layout_centerHorizontal="true"
android:layout_marginBottom="30dp"
android:layout_marginLeft="50dp"
android:childDivider="@android:color/transparent" />
<LinearLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/myExpanded"
android:layout_marginLeft="50dp"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
</ScrollView>
but what happens is ExpandableListView height is wrappeed only item. and here is the snapshot
if i set hieght(ex:android:layout_height="100dp") then exapandapble listview becomes unscrollable
Just make ExpandableListInScrollHelper.java
class for making proper scroll and add below method.
public static void getExpandableListViewSize(ExpandableListView myListView) {
ListAdapter myListAdapter = myListView.getAdapter();
if (myListAdapter == null) {
//do nothing return null
return;
}
//set listAdapter in loop for getting final size
int totalHeight = 0;
for (int size = 0; size < myListAdapter.getCount(); size++) {
View listItem = myListAdapter.getView(size, null, myListView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
//setting listview item in adapter
ViewGroup.LayoutParams params = myListView.getLayoutParams();
params.height = totalHeight + (myListView.getDividerHeight() * (myListAdapter.getCount() - 1));
myListView.setLayoutParams(params);
// print height of adapter on log
Log.i("height of listItem:", String.valueOf(totalHeight));
}
Now, add one line of code below set adaptor like
mExpandableList.setAdapter(mAdapter);
ExpandableListInScrollHelper.getExpandableListViewSize(mExpandableList);
And now your problem is solved!!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.