当前位置:首页 > 芯闻号 > 充电吧
[导读]滑动一个View,即移动一个View,改变其当前所处的位置,通过不断改变View的坐标实现滑动的效果。1、Android坐标系:坐标原点在屏幕左上角。 public void getLocationO

滑动一个View,即移动一个View,改变其当前所处的位置,通过不断改变View的坐标实现滑动的效果。

1、Android坐标系:坐标原点在屏幕左上角。

 

public void getLocationOnScreen(int[] location)

Computes the coordinates of this view on the screen. The argument must be an array of two integers. After the method returns, the array contains the x and y location in that order.

Parametersan array of two integers in which to hold the coordinates

View的getLocationOnScreen(int[] location)方法可以获取Android左边系中点的位置。

2、视图坐标系:原点在父视图左上角

在MotionEvent中以getX()、getY()会的视图坐标系中的坐标。

public float getX()  

The visual x position of this view, in pixels. This is equivalent to the translationX property plus the currentleft property.

Returns The visual x position of this view, in pixels.

 

 View提供的获取坐标的方法:到父布局的距离

getTop()

getLeft()

getRight()

getBottom()

MotionEvent提供的方法

getX():点击事件到控件自身左边的距离

getY():点击事件到控件自身顶边的

getRawX():点击事件到屏幕左边的

getRawY():点击事件到屏幕顶边的

location
本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭