先上图
View的这几个参数都是相对于View的父容器来说的。
- top是左上角纵坐标,获取方式Top= getTop();
- left是左上角横坐标。获取方式Left= getLeft();
- bottom是右下角纵坐标。获取方式Bottom= getBottom;
- right是右下角横坐标。获取方式Right= getRight();
因此View的宽高:
width = right - left;
height = bottom - top;
Android3.0开始,View增加了几个参数x、y、translationX和translationY。x和y是View左上角的坐标,而translationX和translationY是View左上角相对于父容器的偏移量。这几个参数也是相对于父容器。
translationX和translationY的默认值是0。
x = left + translationX;
y = top + translationY;
注意
View在平移过程中,top和left表示的是原始左上角的位置信息,其值并不会发生改变,此时改变的是x、y、translationX和translationY这四个参数。
本文详细解析了Android中View的坐标系统与尺寸计算方法,包括top、left、bottom、right等基本属性及其在不同API版本间的演变。同时介绍了从Android 3.0开始新增的x、y、translationX及translationY等参数,并解释了这些参数如何影响View的位置与偏移。
1万+

被折叠的 条评论
为什么被折叠?



