解決ScrollView嵌套ListView高度的問題

public static void setListViewHeight(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    int totalHeight = 0;
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(1, 1);
        totalHeight += listItem.getMeasuredHeight();
    }
    ViewGroup.LayoutParams par = listView.getLayoutParams();
    par.height = totalHeight
            + (listView.getDividerHeight() * (listAdapter.getCount() - 1))
            + listView.getPaddingTop() + listView.getPaddingBottom();
    listView.setLayoutParams(par);
}
相關文章
相關標籤/搜索