美文网首页
RecyclerView滑动监听

RecyclerView滑动监听

作者: Dean_Zeng | 来源:发表于2017-05-26 09:49 被阅读0次

    RecyclerView监听显示的item位置

     LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
     int position = layoutManager.findFirstVisibleItemPosition();
     LogUtils.d("位置信息"+position);
    

    RecyclerView监听位置监听

     LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
     int position = layoutManager.findFirstVisibleItemPosition();
     View firstVisiableChildView = layoutManager.findViewByPosition(position);
     int itemHeight = firstVisiableChildView.getHeight();
    return (position) * itemHeight - firstVisiableChildView.getTop();
    

    注意:
    以上方法都放在onScrolled中执行

    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    super.onScrolled(recyclerView, dx, dy);
                    //调用方法
                }
            });
    

    相关文章

      网友评论

          本文标题:RecyclerView滑动监听

          本文链接:https://www.haomeiwen.com/subject/ygptfxtx.html