scrollview 中嵌套多个listview的最好解决办法

在scrollview中嵌套多个listview的显示问题.

 

只需要调用如下的方法传入listview和adapter数据即可.

 

/**
* 动态设置ListView组建的高度
*/
public static void setListViewHeightBasedOnChildren(ListView listView,Adapter adapter) {
Adapter listAdapter = (Adapter) listView.getAdapter();
if (listAdapter == null) {
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));
listView.setLayoutParams(params);
}

posted @ 2014-09-23 16:49  北京刘星  阅读(414)  评论(0编辑  收藏  举报