android gesture检测
1、关于on<TouchEvent>的返回值
a return value oftrue
from the individualon<TouchEvent>
methods indicates that you have handled the touch event. A return value offalse
passes 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 returnfalse
fromonDown()
, asGestureDetector.SimpleOnGestureListener
does by default, the system assumes that you want to ignore the rest of the gesture, and the other methods ofGestureDetector.OnGestureListener
never 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 aMotionEvent
via each pointer's index and ID:
- Index: A
MotionEvent
effectively stores information about each pointer in an array. The index of a pointer is its position within this array. Most of theMotionEvent
methods 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
更多相关文章
- android远程控制(一)----发现驱动文件里代码含义
- Android(安卓)ListView 和 BaseAdapter 的使用
- Android中几种数据结构使用
- android Spinner和数值选择器使用demo
- android 输入对话框 确认对话框
- Android(安卓)G711A 音频编解码,去除“吱吱”电流声,附上so下载地
- Android(安卓)使用RecyclerView的方法
- Android(安卓)ViewPager与子控件点击事件冲突的解决方案
- Android(安卓)获取验证码倒计时实现