获取view的坐标值

Left 相对父类的从左边算起子view左边相对父view左边的水平距离;

Right 相对父类的从左边算起子view右边相对父view左边的水平距离;

getWidth =Right  -  left;

 

top相对父类的从上边算起子view上边相对父view上边的水平距离;

Bottom 相对父类的从下边算起子view下边相对父view上边的水平距离;

getHeight= Bottom - top

 

 

viewviewgroud都无getMeasureWidth方法

getwidth() isused to get width of view that has drawn like (view.getwidth() orview.getheight()).getwidth() and getHeight() will only bepopulated after the Layout Phase, that is after onLayout()has been called.

getMeasureWidth() is used to get width of view that not drawn yet. like getmeasuredwidth() and getmeasureheight().example : First call measure view.measure(0,0) and then u can use it withgetmeasuredwidth() and getmeasureheight().

should not usegetwidth/getHeight the values withinonMeasure() or getMeasureWidth()/getMeasureWidth(),since those are only the dimensions the View is initially offered or would liketo have, not necessarily the ones it actually ends up getting.

猜你喜欢

转载自blog.csdn.net/f327888576/article/details/51471458
今日推荐