private void adjustListViewHeight(ListView list) {
ListAdatper adapter = list.getAdapter();
if (adapter == null) {
return;
}
int itemCount = adapter.getCount();
int totalHeight = 0;
for (int i = 0; i < itemCount; i++) {
View item = adapter.getView(i, null, list);
item.measure(0, 0);
totalHeight += item.getMeasuredHeight();
}
ViewGroup.LayoutParams params = list.getLayoutParams();
params.height = totalHeight + (list.getDividerHeight() * (itemCount - 1))
+ list.getPaddingTop() + list.getPaddingBottom();
list.setLayoutParams(params);
}
网友评论