Skip to content

Instantly share code, notes, and snippets.

@Jamp
Created September 20, 2016 19:31
Show Gist options
  • Save Jamp/7ca12b7d5a881e0ec35b64935003b7da to your computer and use it in GitHub Desktop.
Save Jamp/7ca12b7d5a881e0ec35b64935003b7da to your computer and use it in GitHub Desktop.
ListView grow with items
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