/**
* @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);
}
ScrollView与listview并用,布布扣,bubuko.com
原文:http://www.cnblogs.com/clarence/p/3586836.html