Android开发(三十)——ScrollView中ListView的高度自动适应

 

int totalHeight = 0;
for (int i = 0; i < mStrings.length; i++) {
    //pullList ListView
    //mAdapter Adapter
    View listItem = mAdapter.getView(i, null, pullList);
    listItem.measure(0, 0);
    totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = pullList.getLayoutParams();
params.height = totalHeight
        + (pullList.getDividerHeight() * (mAdapter.getCount() - 1));
pullList.setLayoutParams(params);


参考:

1. http://wfkbyni.iteye.com/blog/1545120

posted @ 2015-07-04 16:29  长城的草  阅读(721)  评论(0编辑  收藏  举报