如何在滚动条上获取Recyclerview的热门商品 [英] How to get Top Item of recyclerview on scroll

查看:73
本文介绍了如何在滚动条上获取Recyclerview的热门商品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您给予宝贵的时间阅读此主题. 我正在开发一个Android应用程序,其中recyclerview的项目中有recyclerview.

Thanks for giving your precious time to read this thread. I am developing an android app where there is recyclerview within recyclerview's item.

在滚动时,我想执行一些任务,即recyclerview(父recyclerview)到达父项的第一项的上部位置(即,如果第一项的上部位置完全可见).

I want to perform some task when on scrolling the recyclerview(parent recyclerview) reaches to the upper position of the first item of parent (i.e; if the upper position of the first item is completely visible).

到目前为止,我已经尝试过此方法,但仍无法提供所需的结果

    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            LinearLayoutManager linearLayoutManager1 = (LinearLayoutManager) recyclerView.getLayoutManager();
            int displayedPosition = linearLayoutManager1.findFirstCompletelyVisibleItemPosition();

            if(displayedPosition==0){
            //Is this the place where top position of first item is reached ?

                ((ControllableAppBarLayout) getActivity().findViewById(R.id.app_bar_layout)).expandToolbar(true);
            }


        }
    });

推荐答案

通过使用这两种方法的两种组合,您可以存档所需的内容.

By using two combination of these method you can archive what you needed.

 if (linearLayoutManager1.findFirstVisibleItemPosition() == 0
     && linearLayoutManager1.findFirstCompletelyVisibleItemPosition() == 0) {

    // reach first fully visible item.

}

来自操作问题代码段..

from op question code snippet..

  1. 当心linearLayoutManager1的NullPointerException,请检查null
  2. 当心LinearLayoutManager1的ClassCastException,请检查instanceof

这篇关于如何在滚动条上获取Recyclerview的热门商品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆