Android View系统解析(上)
转载请注明出处:http://blog.csdn.net/singwhatiwanna/article/details/38426471(来自singwhatiwanna的csdn博客)
最近看到了任老师的一篇关于如何模仿安卓L上的reveal的一篇博客,感觉很不错,但是其中涉及到了View的一些比较里层的只是,于是又在老师的博客里面翻来翻去的,果然翻到了关于View的一些系统的介绍,边理解,边转载到自己的博客上面来,在以后的开发过程中肯定也是用的上的....
View中会涉及到一个系统所能使别的最小滑动的距离,也就是TouchSlop,获取这个最小距离的方式为:
<span style="font-size:14px;">ViewConfiguration.get(getContext()).getScaledTouchSlop()</span>
<span style="font-size:14px;">velocityTracker = VelocityTracker.obtain();
velocityTracker.addMovement(event);
velocityTracker.computerCurrentVelocity(1000);
int velocity = (int) velocityTracker.getXVelocity();
...
velocityTracker.recycle();</span>
View上还有一个很方便开发者使用的手势判断GestureDetector,这个手势检测封装好了onTouchEvent(),并且自带上面说到的速度追踪,使用方法为:
<span style="font-size:14px;">boolean consume = mGestureDetector.onTouchEvent(event);</span>
并且还提供了很多接口,
<span style="font-size:14px;">OnGestureListener{
onDown, onSingleTapUp, onFling , onScroll , onLongPress
}</span>
<span style="font-size:14px;">mGestureDetector.setLongPressEnabled(false);</span>
这句话可以处理长按屏幕后无法拖动的现象.