1、关于on<TouchEvent>的返回值

a return value oftruefrom the individualon<TouchEvent>methods indicates that you have handled the touch event. A return value offalsepasses events down through the view stack until the touch has been successfully handled.

true表示你已经处理了此touch事件,false则会将事件一直传到view栈,直到touch事件被处理。

2、关于onDown()事件

Whether or not you useGestureDetector.OnGestureListener, it's best practice to implement anonDown()method that returnstrue. This is because all gestures begin with anonDown()message. If you returnfalsefromonDown(), asGestureDetector.SimpleOnGestureListenerdoes by default, the system assumes that you want to ignore the rest of the gesture, and the other methods ofGestureDetector.OnGestureListenernever get called.

关于多点触摸:

system generates the following touch events:

  • ACTION_DOWN—For the first pointer that touches the screen. This starts the gesture. The pointer data for this pointer is always at index 0 in theMotionEvent.
  • ACTION_POINTER_DOWN—For extra pointers that enter the screen beyond the first. The pointer data for this pointer is at the index returned bygetActionIndex().
  • ACTION_MOVE—A change has happened during a press gesture.
  • ACTION_POINTER_UP—Sent when a non-primary pointer goes up.
  • ACTION_UP—Sent when the last pointer leaves the screen.

访问多点的touch数据:

You keep track of individual pointers within aMotionEventvia each pointer's index and ID:

  • Index: AMotionEventeffectively stores information about each pointer in an array. The index of a pointer is its position within this array. Most of theMotionEventmethods you use to interact with pointers take the pointer index as a parameter, not the pointer ID.
  • ID: Each pointer also has an ID mapping that stays persistent across touch events to allow tracking an individual pointer across the entire gesture.
 1 private int mActivePointerId; 2   3 public boolean onTouchEvent(MotionEvent event) { 4     .... 5     // Get the pointer ID 6     mActivePointerId = event.getPointerId(0); 7  8     // ... Many touch events later... 9 10     // Use the pointer ID to find the index of the active pointer 11     // and fetch its position12     int pointerIndex = event.findPointerIndex(mActivePointerId);13     // Get the pointer's current position14     float x = event.getX(pointerIndex);15     float y = event.getY(pointerIndex);16 }
View Code

更多相关文章

  1. android远程控制(一)----发现驱动文件里代码含义
  2. Android(安卓)ListView 和 BaseAdapter 的使用
  3. Android中几种数据结构使用
  4. android Spinner和数值选择器使用demo
  5. android 输入对话框 确认对话框
  6. Android(安卓)G711A 音频编解码,去除“吱吱”电流声,附上so下载地
  7. Android(安卓)使用RecyclerView的方法
  8. Android(安卓)ViewPager与子控件点击事件冲突的解决方案
  9. Android(安卓)获取验证码倒计时实现

随机推荐

  1. Android(安卓)开发实践 ViewGroup 实现左
  2. Design Widget
  3. Android(安卓)Studio 百度地图开发
  4. WIFI移植手记
  5. TabWidget/TabHost的两种使用方法
  6. Android(安卓)Studio中的build.gradle文
  7. Android中menu详解
  8. Android(安卓)近百个项目的源代码,覆盖And
  9. android selector下的设置背景属性值
  10. android布局