1

Can anyone tell why, a Horizontal RecyclerView inside a ListView return wrong computeHorizontalScrollOffset() when it is scrolled to end?

enter image description here

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 Log.i data: enter image description here

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.

Beeing Jk
  • 3,796
  • 1
  • 18
  • 29

0 Answers0