ViewPropertyAnimators (http://developer.android.com/reference/android/view/ViewPropertyAnimator.html) have two types of methods to move Views around:
translateX() vs x(
The documentation states that X
and Y
properties are absolute positions, while translationX
and translationY
are referred to the LEFT and TOP properties respectively.
So, the difference between animate().x()
and animate().translationX()
is that one animates to an absolute value, while the other animates to a still absolute value but determined by the view LEFT
and TOP
values.
By contrast, animate().xBy()
and animate().translationXBy()
increase (algebraically) the property value by the specified amount.
That is the origin of the "some mathematics" cited above.
x
refers to the current visual position of a view in the x-axis. So, for example, when you animate x
by calling view.animate().x(10)
, the view will be animated such that it moves to x=10
. Let's just assume that view was in a position of (100, 150) when you started the animation. By the end of the animation, the view will be in (10, 150).
Now, contrast this with translationX
. If you animate this property by calling view.animate().translationX(10)
, you are moving a view by that many pixels in the x-axis. Let's assume the same example, where the view was in a position of (100, 150) when you started the animation. By the end of the animation, the view will be in (110, 150).
Hope that clarifies the difference between x()
and translationX()
. The difference is the same for y()
and translationY()
, but in the y-axis.
In my view, xBy()
achieves the same effect as translationX()
but by using the x
property itself plus some mathematics. yBy()
and translationY()
are the equivalents in the y-axis.
Hope that clarifies...
A visualization of translationY(), y(), yBy(), translationYBy() methods are bellow
translationX and translationY: These properties control where the View is located as a delta from its left and top coordinates which are set by its layout container.
x and y: These are simple utility properties to describe the final location of the View in its container, as a sum of the left and top values and translationX and translationY values.
Animate views docs