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 code but no result.
HorizontalScrollView: auto-scroll to end when new Views are added?
please check the solution here. https://github.com/ritesh-bhavsar86/StockAutoScroll
first create runnable:
final int duration = 10;
final int pixelsToMove = 30;
private final Handler mHandler = new Handler(Looper.getMainLooper());
private final Runnable SCROLLING_RUNNABLE = new Runnable() {
@Override
public void run() {
rv_autoScroll.smoothScrollBy(pixelsToMove, 0);
mHandler.postDelayed(this, duration);
}
};
then after setadapter() to the recyclerView use following:
rv_autoScroll.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int lastItem = layoutManager.findLastCompletelyVisibleItemPosition();
if(lastItem == layoutManager.getItemCount()-1){
mHandler.removeCallbacks(SCROLLING_RUNNABLE);
Handler postHandler = new Handler();
postHandler.postDelayed(new Runnable() {
@Override
public void run() {
rv_autoScroll.setAdapter(null);
rv_autoScroll.setAdapter(madapter);
mHandler.postDelayed(SCROLLING_RUNNABLE, 2000);
}
}, 2000);
}
}
});
mHandler.postDelayed(SCROLLING_RUNNABLE, 2000);
rv_autoScroll is recyclerview
and
layoutmanager is LayoutManager which set to recyclerview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With