Answer the question
In order to leave comments, you need to log in
How to do horizontal scrolling in android?
I'm looking for a way to make cyclic horizontal scrolling in android, preferably using standard platform tools for API version no higher than 15.
Answer the question
In order to leave comments, you need to log in
As a fairly simple option:
1) Take RecyclerView, make it horizontal:
2) Loop it by making a custom adapter:
class CustomAdapter extends RecyclerView.Adapter<Holder>{
private List<Item> items;
...
@Override
public void onBindViewHolder(Holder holder, int position) {
int actualPosition = position % items.size(); //Используем вместо position
}
@Override
public int getItemCount() {
return Integer.MAX_VALUE; //важно, обеспечивает "бесконечность" скролла
}
...
}
recyclerView.setAdapter(new CustomAdapter());
recyclerView.scrollToPosition(Integer.MAX_VALUE / 2); // тут подбираем число, чтобы нужный контент был на экране, я взял просто посередине.
You need to scroll so that the scroll is "infinite" in both directions. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question