
類關(guān)系圖
- view的坐標(biāo)
- top,left,right,bottom是指view相對(duì)于父容器的坐標(biāo)
- 從android3.0開始,增加了x,y,translationX,translationY.這四個(gè)參數(shù)也是相對(duì)于父容器的偏移量,在平移時(shí)top和left表示原始左上角的位置信息,并不會(huì)發(fā)生改變。改變的就是這四個(gè)參數(shù)。
x = left+translationX,y = top+translationY
- MotionEvent
- 手指接觸屏幕會(huì)產(chǎn)生一系列事件:ACTION_DOWN,ACTION_MOVE,ACTION_UP
- getX/getY返回相對(duì)于當(dāng)前view左上角的坐標(biāo),getRawX/getRawY返回的是相對(duì)于手機(jī)屏幕左上角的坐標(biāo)。
- 在onTouchEvent中使用VelocityTracker追蹤手指的滑動(dòng)速度:
<pre>
VelocityTracker velocityTracker = VelocityTracker.obtain();
velocityTracker.addMovement(event);
velocityTracker.computeCurrentVelocity(1000);//時(shí)間間隔毫秒
int xVelocity = (int) velocityTracker.getXVelocity();
int yVelocity = (int) velocityTracker.getYVelocity();
velocityTracker.clear();//重置
velocityTracker.recycle();//回收
</pre>
- GestureDetector實(shí)現(xiàn)監(jiān)聽雙擊
參考GestureDetector類及其用法