Another questions about setting position of a view. If you want to move a view around then you can do setX, setTranslationX, setLeft or LayoutParam.leftMargin Offcourse there is also overriding the onDraw method and using Matrix/Bitmap/Canvas operation.
I was wondering what's the difference. Do they all ultimetly adjust the same value which is x coordinate of the view? It would be good to have it all in one post for future readers as well
So far I know,
Anyone can shed light on the differences and if they impact different properties or the same property?
I believe that the main difference between setLeft and setX()
is that setLeft()
is relative to its parent view, where setX()
just sets the position relative to the whole screen, which is the same as setTranslationX()
.
In setLeft()
terms it means that the layout system can change its layout position. For example if we would use setLeft while scrolling through a RecyclerView the system would change its position accordingly, so the proper use in this case would be setX()
.
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