Can anyone tell why, a Horizontal RecyclerView inside a ListView return wrong computeHorizontalScrollOffset()
when it is scrolled to end?
I set a holder.recyclerView.addOnScrollListener()
in my ListView adapter, getView() like this:
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
float horizontalScrollOffSet = recyclerView.computeHorizontalScrollOffset();
int expectedPosition = Math.round((horizontalScrollOffSet + padding - firstItemWidth) / itemWidth);
Log.i("position", "horizontalScrollOffSet:"+horizontalScrollOffSet+",expectedPosition:"+expectedPosition);
}
}
The offset figures are supposed to be increasing while the view is scrolled from left to right, everything works fine except when it's scrolled to the end, it just returned a smaller figure. I really have no idea about this but I need it to compute the items' center points. Can anyone please guide? :'(
From what I tried out, the RecyclerView works fine when last padding item size is set to the same as main item size.