调用方法后通过LayoutParam方式对ListView高度进行设置。
//获取Listview所有Item高度总和
public int getAllItemListViewHeight(ListView listView){
ArrayAdapter adapter = (ArrayAdapter) listView.getAdapter();
int totalHeight = -1;// 总的高度
try{
if(adapter!=null){
for (int i = 0; i < listView.getCount(); i++) {
View listItem = adapter.getView(i, null, listView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
//加上分割线高度
totalHeight += (listView.getDividerHeight() * (adapter.getCount() - 1));
}else{
//will return -1
}
}catch (Exception e){
totalHeight = -1;
}
return totalHeight;
}