ScrollView与listview并用
/**
* @Title: setListViewHeightBasedOnChildren
* @Description: 计算listview高度
* @param @param listView 设定文件
* @return void 返回类型
* @throws
*/
public void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = 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();
}
LayoutParams params = listView.getLayoutParams();
params.height = totalHeight+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
}
posted on 2014-03-07 17:15 clarenceV1 阅读(119) 评论(0) 编辑 收藏 举报