what is the difference between View.getLeft() vs View.getScrollX() ? Please don't copy and paste definition from the documentation, because I am about to do it for you below
getScrollX()
Return the scrolled left position of this view.
getLeft()
Left position of this view relative to its parent
I think those 2 values should be the same, but a sample program of mine, if i do View.scrollBy(20, 0) i see that getScrollX() will return 20 and the view is actually moved to the right, but getLeft() remains to be zero
i am confused, because if visually the view is being scrolled to the right by 20px, its left position should be updated as well, but it is still 0
obviously they can't be the same, otherwise there is no need to have 2 different methods that return the same result
please help
getLeft()
returns the views location relative to its parent. How it has scrolled does not impact this at all. Scrolling impacts the contents of the view, not its location.
a quote from the android documentation regarding getLeft():
For instance, when getLeft() returns 20, that means the view is located 20 pixels to
the right of the left edge of its direct parent.
getScrollX()
, on the other hand, lets you know how the content in the view has moved.
View.scrollBy(20,0) affects the content in the view (like subviews of the view) and doesn't actually move the view relative to the view's parent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With