I'm using a Scrollview
for an infinite "Time Picker Carousel" and found out, that it is not the best approach (last question)
Now, I found the Recycler View but I am unable to get the current scroll offset in X direction of the recyclerView? (Let's say each item is 100px width, and the second item is only visible to 50%, so the scroll-offset is 150px)
- all items have the same width, but therer is some gap before the first, after the last item
recyclerView.getScrollX()
returns 0
(docs say: initial scroll value)
- the
LayoutManager
has findFirstVisibleItemPosition
, but I cannot calculate the X offset with that
UPDATE
I just found a way to keep tracking the X-Position, while updating the value with the onScrolled
callback, but I would prefer getting the actual value instead of tracking it all the time!
private int overallXScroll = 0;
//...
mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
overallXScroll = overallXScroll + dx;
Log.i("check","overallXScroll->" + overallXScroll);
}
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…