获得View在布局和屏幕上的位置(getLeft()以及getLocationOnScreen())
2012-11-18 03:09
549 查看
在一个布局中有一个控件View v.
可以通过以下方法可得到其在布局中的位置:
v.getLeft();
v.getRight();
v.getBottom();
v.getTop();
这样就得到控件本身的上下左右四个方位相对于parent的位置.即自身的上下左右距离parent有几个像素
但是请注意:getLeft()表示自己的左边距离parent的左边的距离
但是请注意:getRight()表示自己的右边距离parent的左边的距离
但是请注意:getTop()表示自己的上边距离parent的上边的距离
但是请注意:getBottom()表示自己的下边距离parent的上边的距离
同理:v.layout(l, t, r, b)方法中的参数也是如此
使用如下方法得到,某控件在屏幕上的位置:
int v_location []=new int [2];
v.getLocationOnScreen(v_location);
int step_ball_location_0=v_location[0];
int step_ball_location_1=v_location[1];
即step_ball_location_0和step_ball_location_1即为位置
注意:不可以在OnCreate()方法中执行!!!!此时的step_ball_location_0和step_ball_location_1均为0
可以通过以下方法可得到其在布局中的位置:
v.getLeft();
v.getRight();
v.getBottom();
v.getTop();
这样就得到控件本身的上下左右四个方位相对于parent的位置.即自身的上下左右距离parent有几个像素
但是请注意:getLeft()表示自己的左边距离parent的左边的距离
但是请注意:getRight()表示自己的右边距离parent的左边的距离
但是请注意:getTop()表示自己的上边距离parent的上边的距离
但是请注意:getBottom()表示自己的下边距离parent的上边的距离
同理:v.layout(l, t, r, b)方法中的参数也是如此
使用如下方法得到,某控件在屏幕上的位置:
int v_location []=new int [2];
v.getLocationOnScreen(v_location);
int step_ball_location_0=v_location[0];
int step_ball_location_1=v_location[1];
即step_ball_location_0和step_ball_location_1即为位置
注意:不可以在OnCreate()方法中执行!!!!此时的step_ball_location_0和step_ball_location_1均为0
相关文章推荐
- 获得View在布局和屏幕上的位置(getLeft()以及getLocationOnScreen())
- 使用getLocationInWindow或getLocationOnScreen获得View在屏幕中的坐标
- android 中获取当前焦点所在屏幕中的位置 view.getLocationOnScreen(location)
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- Android ListView在增加HeaderView之后使用getLocationInWindow和getLocationOnScreen获得值不正确的解决方法
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- Android中getLocationOnScreen和getLocationInWindow 获取屏幕大小
- LocationOnScreen-控件在手机屏幕中的位置坐标
- 开发android中,解决View.getLocationOnScreen为0