Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between setX and setTranslationX

Tags:

android

What is the difference between setX and setTranslationX on a view? They seem to be the same for me yet they exist both on the android platform.

Thanks

like image 515
Snake Avatar asked Nov 25 '25 18:11

Snake


2 Answers

From the docs for setX():

Sets the visual x position of this view, in pixels. This is equivalent to setting the translationX property to be the difference between the x value passed in and the current left property.

like image 117
Emmanuel Avatar answered Nov 27 '25 06:11

Emmanuel


setTranlsationX() as a relative offset and setX() is a fixed position.

like image 40
M Karimi Avatar answered Nov 27 '25 07:11

M Karimi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!