解决方案:
通过代码计算ListView实际使用的高度
/**
* @return返回ListView的LayoutParams
*/
public staticViewGroup.LayoutParams getHeight(Adapter sa,ListView lv){
View itemView = sa.getView(0, null, lv);
itemView.measure(0,0);
inth= itemView.getMeasuredHeight();
inttotalHeight = sa.getCount() * h ;
ViewGroup.LayoutParamsparams = lv.getLayoutParams();
//总高度=总的item的高度+item之间的分割线高度
params.height = totalHeight+ (lv.getDividerHeight() * (sa.getCount()- 1));
returnparams;
}
listView.setAdapter(sa);
//在设置Adapter之后再设置ListView的显示
ViewGroup.LayoutParamsmaxheight = new calcListViewHeightHelper().getHeight(sa, listView);
listView.setLayoutParams(maxheight);