在gridview项目的末尾停止滚动

时间:2014-07-15 08:12:23

标签: android gridview scroll

我使用Helper类将gridview放在scrollview中

public class Helper {
public static void getListViewSize(GridView myListView) {
    ListAdapter myListAdapter = myListView.getAdapter();
    if (myListAdapter == null) {
        // do nothing return null
        return;
    }
    // set listAdapter in loop for getting final size
    int totalHeight = 0;
    for (int size = 0; size < myListAdapter.getCount(); size++) {
        View listItem = myListAdapter.getView(size, null, myListView);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }
    // setting listview item in adapter
    ViewGroup.LayoutParams params = myListView.getLayoutParams();
    params.height = totalHeight
            + (myListView.getHeight() * (myListAdapter.getCount() - 1));
    myListView.setLayoutParams(params);
    // print height of adapter on log
    Log.e("height of listItem:", String.valueOf(totalHeight));
}
}

并将此课程用作

adapter = new RSSReaderGridAdapter(context, mostLatestItems);
    gridView.setAdapter(adapter);
    Helper.getListViewSize(gridView);

它工作正常..但是当我滚动页面滚动时不停在gridview的最后一项...它继续滚动..

1 个答案:

答案 0 :(得分:0)

可能滚动了ScrollView。如果想要滚动GridView,你应该覆盖&#34; onInterceptTouchEvent&#34;。