android中如何让listview的内容全部显示出来
?
?
? ?注意,如果listitem里面有textview的话,就当一行处理进行截取数字。
?
? ?public static void setListViewHeightBasedOnChildren(ListView listView) {
/** * 动态改变listView的高度 * @param pull */private void setPullLvHeight(ListView pull){int totalHeight = 0; 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); }