View的位置是由它的四个顶点决定,对应它的四个属性:Left、Top、Right、Bottom
Left、Top、Right、Bottom四个参数在View的平移过程中不会改变
- Left = getLeft();
- Top = getTop();
- Right = getRight();
- Bottom = getBottom();
3.0后,view增加了新的几个参数:x、y、translationX、translationY;x、y是view的左上角坐标,translationX、translationY是它的初始位置的偏移量
- x = getX();
- y = getY();
- translationX = getTranslationX();
- translationY = getTranslationY();
由于整个平移过程中Left、Top、Right、Bottom四个参数不会改变,所以
- x = left + translationX;
- y = top + translationY;
// View源码
public float getX() {
return mLeft + getTranslationX();
}
public float getY() {
return mTop + getTranslationY();
}
getScrollX:返回视图已经移出屏幕左边缘距距离,移出为正,未移出为负
getScrollY:返回视图已经移出屏幕顶部边缘距距离,移出为正,未移出为负
参考博客:
https://blog.csdn.net/weixin_39251617/article/details/79622532