View的移动方式
View的移动方式
常见的View的移动方式有setX()/setY()、setTranslationX()/setTranslationY()、动画、scrollTo/scrollBy等。因为View的属性比较多。view使用不同的移动方式,受影响的是那些变量属性已经方法。以及配合使用时会产生何种效果。比如view的getX/Y、getSrollX/Y、getTranslationX/Y、getLeft/top/right/bottom、点击事件触发区域等等,是否会受到影响改变,由哪些所影响?
各个移动方式对属性的验证:
1、getX()、getY()
2、getScrollX() 、getScrollY()
3、getTranslationX() 、getTranslationY()
4、getLeft()、 getTop()、 getRight()、 getBottom()(坐标位置是否改变)
5、点击事件触发区域是否改变
6、是否会影响同层级的其他view的位置
7、超过父View是否绘制
View坐标系
view的位置大小由以下参数决定:
1.mLeft、mRight、mTop、mBottom 这四个参数相对于父view
2.mScrollX、mScrollY
3.translationX、translationY
4.getX()、getY()
- 获取高宽:
public final int getWidth() {
return mRight - mLeft;
}
public final int getHeight() {
return mBottom - mTop;
}
在Activity中布局完成后,我们可以通过View一些方法获取这些参数信息:
//left,top,right,bottom值的获取
int left = getLeft();
int top = getTop();
int right = getRight();
int bottom = getBottom();
public final int getLeft() {
return mLeft;
}
scrollTo()/scrollBy()
scrollTo()和s