第一能够嵌套而并能够滑动ScrollView
第二listview能一次全部加载显示出来,容易出现只能显示一行内容但是可以滑动显示出来
1,
public class BulkUtility { public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { 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); } }调用
BulkUtility.setListViewHeightBasedOnChildren(listview1); BulkUtility.setListViewHeightBasedOnChildren(listview2);
一般来说此时可以完成嵌套滑动,但是还不够,只能显示出一行listview,此时我采用的方法是重写listview方式、
重写protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); }基本可以ok了