Android: How to get the current X offset of RecyclerView?

前端 未结 6 1755
逝去的感伤
逝去的感伤 2020-12-02 07:48

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 Recycl

6条回答
  •  半阙折子戏
    2020-12-02 08:03

    public class CustomRecyclerView extends RecyclerView {
    
        public CustomRecyclerView(Context context) {
            super(context);
        }
    
        public CustomRecyclerView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public CustomRecyclerView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        public int getHorizontalOffset() {
            return super.computeHorizontalScrollOffset();
        }
    }
    

    Than where you need to get the offset:

    recyclerView.getHorizontalOffset()
    

提交回复
热议问题