GridView向上滚动并向下滚动

时间:2014-05-07 08:39:44

标签: android gridview

我有这个代码,当你向下或向上滚动gridview时,它将隐藏顶部容器。我的问题是它只会在向上或向下滚动然后释放时执行。

如果用户向下滚动而不释放它,我该如何隐藏我的顶部容器。?

类似于Scrolling tricks

mygrid.setOnScrollListener(new OnScrollListener(){

      @Override
      public void onScrollStateChanged(AbsListView view, int scrollState) {
        // TODO Auto-generated method stub
        final GridView lw = (GridView) view;

        if (view.getId() == lw.getId()) {
          final int currentFirstVisibleItem = lw.getFirstVisiblePosition();

          if (currentFirstVisibleItem > mLastFirstVisibleItem) {
            mTopContainer.setVisibility(View.GONE);
            //Scroll down
          } else if (currentFirstVisibleItem < mLastFirstVisibleItem) {
            mTopContainer.setVisibility(View.VISIBLE);
            //Scroll Up 
          }

          mLastFirstVisibleItem = currentFirstVisibleItem;
        }
      } 

1 个答案:

答案 0 :(得分:0)

您可以将滚动逻辑放入OnScrollListener的onScroll方法中:

    public abstract void onScroll (AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        //in this method also some parameters are automatically passed, so you don't have to get them from the GridView
    }