先来看看官方文档的定义:
public final int getLeft ()
Added in API level 1
Left position of this view relative to its parent.
Returns
The left edge of this view, in pixels.
public float getX ()
Added in API level 11
The visual x position of this view, in pixels. This is equivalent to the translationX property plus the current left property.
Returns
The visual x position of this view, in pixels.
public float getTranslationX ()
Added in API level 11
The horizontal location of this view relative to its left position. This position is post-layout, in addition to wherever the object's layout placed it.
Returns
The horizontal position of this view relative to its left position, in pixels.
这里总共有三种值,
1、left(getLeft()):View相对于父View的左边坐标。
这个值不会随着View的属性(transitionX和X)改变。
View在layout的时候,会调用setFrame函数来改变left的值。
客户端也可以直接调用setLeft来改变left值。
left值改变后,View的大小也会改变。因为View的大小是right - left。
2、x(getX()): View实际显示的左边坐标。它的值是 translationX + left
3、tanslationX(getTranslationX):View 相对于left的位移。
属性动画改变的是x和translationX的值,没有改变left的值。
所以,这三个值的关系是:
x = translationX + left。