Android View seems to have 2 methods which appears to do some very similar functionality.
1] setTranslationX
& setTranslationY
2] offsetLeftAndRight
& offsetTopAndBottom
Can anybody tell me how these are different? What is the scenarion in which [1] can be used but not [2]? and vise-versa?
offsetLeftAndRight()
and offsetTopAndBottom()
alter the result of the layout pass, while setTranslationX()
and setTranslationY
add an additionnal offset on top of the layout result, the default value being 0.
One consequence is that the leftAndRight / TopAndBottom offset is reset with every layout pass (e.g. triggered by requestLayout()
) while the translation is not.
My understanding is that offsetLeftAndRight()
and offsetTopAndBottom()
are mostly useful if you write your own Layout, while setTranslationX()
and setTranslationY
are generic methods to tweak the result of a layout.
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