Android Horizontal Auto scroll in Recycler view

前端 未结 2 1511
心在旅途
心在旅途 2021-01-06 07:05

I have two values in list and displaying that in horizontal list view using Recycler view. Here I need to auto scroll the horizontal list unlimited. I tried with the below c

2条回答
  •  臣服心动
    2021-01-06 07:33

    trainigItemRV.addOnScrollListener(new RecyclerView.OnScrollListener() {
                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    super.onScrolled(recyclerView, dx, dy);
                    int lastItem = linearLayoutManager.findLastCompletelyVisibleItemPosition();
                    if(lastItem == linearLayoutManager.getItemCount()-1){
                        mHandler.removeCallbacks(SCROLLING_RUNNABLE);
                        Handler postHandler = new Handler();
                        postHandler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                trainigItemRV.setAdapter(null);
                                trainigItemRV.setAdapter(productsTrainingItemAdapter);
                                mHandler.postDelayed(SCROLLING_RUNNABLE, 2000);
                            }
                        }, 2000);
                    }
                }
            });
            mHandler.postDelayed(SCROLLING_RUNNABLE, 2000);
    
    This Works For me..
    

提交回复
热议问题