如何在scrollview中正确设置listview高度?

时间:2015-02-15 15:21:18

标签: android listview

我在scrollview中使用listview并使用此代码更新listview高度:

// method to expand the height of listview
public void updateListViewHeight(ListView list) {
    CustomeAdapter myListAdapter = (CustomeAdapter) list.getAdapter();
    if (myListAdapter == null) {
        return;
    }
    // get listview height
    int totalHeight = 0;
    // int adapterCount = myListAdapter.getCount();
    for (int size = 0; size < Math.max(shoutsList.size(), postsList.size()); size++) {
        View listItem = myListAdapter.getView(size, null, list);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }
    // Change Height of ListView
    ViewGroup.LayoutParams params = list.getLayoutParams();
    params.height = totalHeight
            + (list.getDividerHeight() * (shoutsList.size() - 1));
    list.setLayoutParams(params);
}

问题是我在用户向下滚动时从服务器请求新数据,但是当我更新listview高度时,它会自动滚动并自动请求数据

0 个答案:

没有答案