Android View基础知识点

来源:互联网 发布:佐川一政 知乎 编辑:程序博客网 时间:2024/06/10 23:18

View的位置参数

top,left,right,bottom.

width = right - left. height = bottom - top.

x,y,translationX,translationY.

translationX,translationY是View左上角相对于父容器的偏移量。

x = left + translationX. y = top + translationY.

MotionEvent

ACTION_DOWN

ACTION_MOVE

ACTION_UP

TouchSlop

touchSlop是系统所能识别出的被认为是滑动的最小距离。8dp。

VelocityTracker

速度追踪,用于追踪手指在滑动过程中的速度,包括水平和竖直方向的速度。

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

手势检测,用于辅助检测用户的单击,滑动,长按,双击等行为。

GestureDetector mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener(){});
第二个参数中有选择地实现OnGestureListener和OnDoubleTapListener中的方法。

接管目标View的onTouchEvent方法。
boolean consume = mGestureDetector.onTouchEvent(arg0);return consume;

Scroller

弹性滑动对象,用于实现View的弹性滑动。


原创粉丝点击