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

后端 未结 4 1536
甜味超标
甜味超标 2021-02-03 19:58

ViewPropertyAnimators (http://developer.android.com/reference/android/view/ViewPropertyAnimator.html) have two types of methods to move Views around:

translateX() vs x(

4条回答
  •  不要未来只要你来
    2021-02-03 20:32

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

提交回复
热议问题