重新设置ListView的高度
/**
* 设置listview高度,注意listview子项必须为LinearLayout才能调用该方法
* @param listview listview
*
*/
public static void setListViewHeight(ListView listview)
{
int totalHeight = 0;
ListAdapter adapter= listview.getAdapter();
if(null != adapter)
{
for (int i = 0; i
{
View listItem = adapter.getView(i, null, listview);
if (null != listItem)
{
listItem.measure(0, 0);//注意listview子项必须为LinearLayout才能调用该方法
totalHeight += listItem.getMeasuredHeight();
}
}
ViewGroup.LayoutParams params = listview.getLayoutParams();
params.height = totalHeight + (listview.getDividerHeight() * (listview.getCount() - 1));
listview.setLayoutParams(params);
}
}
原文:http://www.cnblogs.com/zmc/p/3793060.html