How to adjust ListView height when there is an advanced ListView built into ListView

In action, there is a ListView with the appropriate adapter. Each item in this ListView has an ExpandableListView extension with an associated adapter.

Initially, there are only two elements in a ListView, and all expandable lists are not expandable. Currently, the height of the ListView does not exceed the height of the screen (suppose the height of the screen is 800 and the height of the ListView is 600.). enter image description here

Then I click the dropdown listview in the first item, the extensible view of the list expands. However, the height of the ListView does not change (an empty area still exists). enter image description here

Is there a way to adjust the height of the list so that the empty area can be removed when I click to expand the expanded view of the list? Thanks.

+4
source share
1 answer

http://www.java2s.com/Code/Android/UI/setListViewHeightBasedOnChildren.htm

It helps me. You basically have to keep track of the height of the layout. And use setLayoutParams() and requestLayout() to configure it inside the onGroupExpand and onGroupCollapseListener .

+2
source

Source: https://habr.com/ru/post/1412936/


All Articles