public static void setListViewHeightBasedOnChildren(ListView listView, int attHeight) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
// pre-condition
return;
}
int totalHeight = 0;
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount()-1)) + attHeight;
listView.setLayoutParams(params);
}
scroview嵌套listview,listview全部展开
最新推荐文章于 2023-04-24 15:49:45 发布