/**
* 计算listview高度
*
* @param pull
*/
public void setPullLvHeight(ListView pull) {
int totalHeight = 0;
ListAdapter adapter = pull.getAdapter();
for (int i = 0, len = adapter.getCount(); i < len; i++) { // listAdapter.getCount()返回数据项的数目
View listItem = adapter.getView(i, null, pull);
listItem.measure(0, 0); // 计算子项View 的宽高
totalHeight += listItem.getMeasuredHeight(); // 统计所有子项的总高度
}
ViewGroup.LayoutParams params = pull.getLayoutParams();
params.height = totalHeight
+ (pull.getDividerHeight() * (pull.getCount() - 1));
pull.setLayoutParams(params);
}
* 计算listview高度
*
* @param pull
*/
public void setPullLvHeight(ListView pull) {
int totalHeight = 0;
ListAdapter adapter = pull.getAdapter();
for (int i = 0, len = adapter.getCount(); i < len; i++) { // listAdapter.getCount()返回数据项的数目
View listItem = adapter.getView(i, null, pull);
listItem.measure(0, 0); // 计算子项View 的宽高
totalHeight += listItem.getMeasuredHeight(); // 统计所有子项的总高度
}
ViewGroup.LayoutParams params = pull.getLayoutParams();
params.height = totalHeight
+ (pull.getDividerHeight() * (pull.getCount() - 1));
pull.setLayoutParams(params);
}