首页 > 代码库 > android _scrollview嵌套listview出现高度显示不全解决方案

android _scrollview嵌套listview出现高度显示不全解决方案

只要在工具类里写上这一段代码:
/** * scrollview嵌套listview显示不全解决 * @param listView */ public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { // pre-condition return; } int totalHeight = 0; for (int i = 0; i < listAdapter.getCount(); i++) { View listItem = listAdapter.getView(i, null, listView); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); }

 

然后在setdapter以后调用该方法就解决问题了。

android _scrollview嵌套listview出现高度显示不全解决方案