Created
September 20, 2016 19:31
-
-
Save Jamp/7ca12b7d5a881e0ec35b64935003b7da to your computer and use it in GitHub Desktop.
ListView grow with items
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int totalHeight = 0; | |
for (int i = 0; i < adapter.getCount(); i++) { | |
View listItem = adapter.getView(i, null, listView); | |
listItem.measure(0, 0); | |
totalHeight += listItem.getMeasuredHeight(); | |
} | |
ViewGroup.LayoutParams params = listView.getLayoutParams(); | |
params.height = 200 * (arrayData.size() + 1); | |
params.height = totalHeight + (listView.getDividerHeight() * (listView.getCount() - 1)); | |
listView.setLayoutParams(params); | |
listView.requestLayout(); | |
listView.setAdapter(adapter); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment