scrollview+listview的高度自动适应

很多时间我们在scorllview中嵌入listview的时候,都只能看到listview显示一行数据,而我们的要求是显示多行,即我们数据的行数,那么请看下面的代码:

                int totalHeight = 0;//总的高度
for (int i = 0; i < initData(0).size(); i++) { //initData(0).size()数据的行数
View listItem = myAdapter.getView(i, null, list1); //list1,当前listview
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}

ViewGroup.LayoutParams params = list1.getLayoutParams();
params.height = totalHeight
+ (list1.getDividerHeight() * (myAdapter.getCount() - 1));
list1.setLayoutParams(params);

你可能感兴趣的:(ListView,scorllview)