0

In iphone there are methods for getting the content offset values of a scrollview.

How can I implement this in android?

Are there any methods for getting the offset values of a scrollview in android?

user1891910
  • 919
  • 3
  • 18
  • 45

2 Answers2

1

RecyclerView already has method for it. See this for Detail

mRecyclerView.computeHorizontalScrollOffset();
mRecyclerView.computeVerticalScrollOffset();

And for other then RecyclerView use

targetScrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
        @Override
        public void onScrollChanged() {
            int scrollX = targetScrollView.getScrollX();
            int scrollY = targetScrollView.getScrollY();
            Log.d(TAG, "scrollX: " + scrollX);
            Log.d(TAG, "scrollY: " + scrollY);
        }
    });
Community
  • 1
  • 1
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
0

I think padding is what you are looking for.

You can get them from ScrollView by calling getLayoutParams on it and use the getPadding...() functions of the LayoutParams class.

http://developer.android.com/reference/android/view/View.html#getLayoutParams%28%29

http://developer.android.com/reference/android/view/View.html#getPaddingLeft%28%29

Capella
  • 881
  • 3
  • 19
  • 32
viplezer
  • 5,519
  • 1
  • 18
  • 25
  • I wants to get the offset value, so that I can use that offset value for setting offset to another scrollview,so that I can change colors while scroling. – user1891910 Dec 02 '13 at 13:46
  • Sorry, I misunderstood your question: is this thread useful for you: http://stackoverflow.com/questions/7870546/synchronizing-two-horizontal-scroll-views-in-android ? – viplezer Dec 02 '13 at 13:57