android view(1) 基础知识

一、view的坐标

1.top,left,right,bottom是指view相对于父容器的坐标

2.从android3.0开始,增加了x,y,translationX,translationY.这四个参数也是相对于父容器的偏移量,在平移时top和left表示原始左上角的位置信息,并不会发生改变。改变的就是这四个参数。

x = left+translationX,y = top+translationY

二、MotionEvent

1.getX/getY返回相对于当前view左上角的坐标,getRawX/getRawY返回的是相对于手机屏幕左上角的坐标。

2.在onTouchEvent中追踪滑动速度:

VelocityTracker velocityTracker = VelocityTracker.obtain();

velocityTracker.addMovement(event);

velocityTracker.computeCurrentVelocity(1000);//时间间隔毫秒

int xVelocity = (int) velocityTracker.getXVelocity();

int yVelocity = (int) velocityTracker.getYVelocity();

velocityTracker.clear();//重置

velocityTracker.recycle();//回收

三、GestureDetector实现监听双击

参考http://www.cnblogs.com/rayray/p/3422734.html

猜你喜欢

转载自smartblack.iteye.com/blog/2307901