What is the difference between ViewPropertyAnimator's translateYBy() vs yBy() methods?

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.


A visualization of translationY(), y(), yBy(), translationYBy() methods are bellow


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...