Android difference between View.getLeft () and View.getScrollX ()

what's the difference between View.getLeft () vs View.getScrollX ()? Please do not copy or paste the definition from the documentation, because I am going 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 these 2 values ​​should be the same, but an example of my program, if I do View.scrollBy (20, 0), I see that getScrollX () will return 20, and the view will actually be moved to the right, but getLeft () will remain equal zero

I am confused because if visually the view scrolls right 20 pixels, its left position should also be updated, but it is still 0

obviously they cannot be the same, otherwise there is no need to have two different methods that return the same result

please, help

+6
source share
1 answer

getLeft() returns the location of the views relative to its parent. How it scrolls, it doesn't affect it at all. Scrolling affects the contents of the view, not its location.

quote from 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 content is moved in the view.

View.scrollBy (20.0) affects the content in the view (for example, in the form of views) and does not actually move the view relative to the parent of the view.

+3
source

All Articles