1

recList.getScrollX() line returns always 0, even though recList is scrolled already by user.

protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            final RecyclerView recList = (RecyclerView) findViewById(R.id.userSettingList);

    horizontalScrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {

                @Override
                public void onScrollChanged() {

                        int scrollX0 = recList.getScrollX(); //always returns 0, why?

                    }
                }
            });
        }
János
  • 32,867
  • 38
  • 193
  • 353
  • Are you sure it was scrolled in the X axis? Vertical scrolling (up and down) is scrolling Y, so you'd use getScrollY(). – alzee Aug 01 '16 at 20:55
  • sure, I am debugging and printing out – János Aug 01 '16 at 20:56
  • To be clear, your RecyclerView scrolls *left and right*? – alzee Aug 01 '16 at 20:58
  • 1
    i believe it's because scrollX() is a method from the view, not the recyclerView. on my app i set the Y position by setSelection. not sure how to do it with X. – avjr Aug 01 '16 at 21:03
  • 1
    this link may help you http://stackoverflow.com/questions/2132370/android-listview-getscrolly-does-it-work – avjr Aug 01 '16 at 21:05
  • Thanks @avjr I found there fix. Storing total scrolled distances in a global variable. – János Aug 02 '16 at 17:08

0 Answers0