gesturedetector

GestureDetector类及其用法

不羁的心 提交于 2019-12-09 14:49:51
当用户触摸屏幕的时候,会产生许多手势,例如 down , up , scroll , filing 等等。 一般情况下,我们知道 View 类有个 View.OnTouchListener 内部接口,通过重写他的 onTouch(View v, MotionEvent event) 方法,我们可以处理一些 touch 事件,但是这个方法太过简单,如果需要处理一些复杂的手势,用这个接口就会很麻烦(因为我们要自己根据用户触摸的轨迹去判断是什么手势)。 Android sdk 给我们提供了 GestureDetector ( Gesture :手势 Detector :识别)类,通过这个类我们可以识别很多的手势,主要是通过他的 onTouchEvent(event) 方法完成了不同手势的识别。虽然他能识别手势,但是不同的手势要怎么处理,应该是提供给程序员实现的。 GestureDetector 这个类对外提供了两个接口: OnGestureListener , OnDoubleTapListener ,还有一个内部类 SimpleOnGestureListener 。 GestureDetector.OnDoubleTapListener 接口 :用来通知 DoubleTap 事件,类似于鼠标的双击事件。 1 , onDoubleTap(MotionEvent e) :在 双击的第二下

Set GestureDetector to all child views

独自空忆成欢 提交于 2019-12-09 10:43:36
问题 I would like to add a GestureDetector to all views (view groups) of an activity without assigning it manually to every single view. Right now onFling() is only activated when swiping over the background but not when swiping on e.g. button1. package com.app.example; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.GestureDetector; import android.view.MotionEvent; import android

Flutter: Stack with two images in GestureDetectors: Problem with reordering

佐手、 提交于 2019-12-08 05:06:32
问题 Flutter: I have two images within a stack, each capable of being scaled by dragging it. The two images are positioned one below the other, so they're both fully visible on screen at first. When I drag the top or bottom image, either should become bigger and overlap the other picture. Therefor, the order in my stack has to change depending on which image I panDowned. I made it almost work, but there is problem I just don't understand. Initially, my top image is the "master" image. So, I can

Android GestureDetector with SimpleOnGestureListener within SurfaceView

拟墨画扇 提交于 2019-12-07 10:54:47
问题 public class GameActivity extends Activity { private static final String TAG = "GameActivity"; . . . @Override public boolean onTouchEvent(MotionEvent event) { Log.d(TAG, "+ onTouchEvent(event:" + event + ")"); Log.d(TAG, "- onTouchEvent()"); return super.onTouchEvent(event); } . . . } public class GameView extends SurfaceView implements SurfaceHolder.Callback { private static final String TAG = "GameView"; . . . @Override public boolean onTouchEvent(MotionEvent event) { Log.d(TAG, "+

How can I detect tap on the screen?

我怕爱的太早我们不能终老 提交于 2019-12-06 21:25:50
问题 More specific where do I attach OnGestureListener so that I can detect onSingleTapUp everywhere on the screen, even if an ImageView take up half the screen. Now I have the Listener on the Activity that has an ImageView. But the Listener only fire when I click outside the ImageView. I read and try to understand this but cannot get it right. this code is in the Activity. public boolean onSingleTapUp(MotionEvent e) { //addtext.setText("-" + "SINGLE TAP UP" + "-"); //Log.d(TAG, "- + SINGLE TAP UP

GestureDetector.onTouchEvent(MotionEvent e) calling onLongPress on all gestures

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 05:44:54
I have a custom view on which I want to set long click listener. I am using following code to set the same. final GestureDetector gestureDetector = (new GestureDetector(new GestureDetector.SimpleOnGestureListener() { public void onLongPress(MotionEvent e) { Log.e("test", "Long press detected"); } })); public boolean onTouchEvent(MotionEvent event) { return gestureDetector.onTouchEvent(event); } The problem is on all gestures whether it is a single tap, double tap onLongPress is getting called. I can get the code to working by implementing onDown() method but why this is not working when it is

Flutter- GestureDetector not working with containers in stack

佐手、 提交于 2019-12-05 12:13:33
问题 I have two containers in a stack and both containers have GestureDetector.The OnTap for the first container is working fine but it's not working with another container. The first container is the image and the second one is the green background aligned partially over the first container. new Stack( alignment: Alignment(0.0, 1.44), children: <Widget>[ GestureDetector( onTap: () => _openImage(context), child: Container( width: 340.0, foregroundDecoration: new BoxDecoration( color: Color

Android GestureDetector with SimpleOnGestureListener within SurfaceView

余生长醉 提交于 2019-12-05 12:08:57
public class GameActivity extends Activity { private static final String TAG = "GameActivity"; . . . @Override public boolean onTouchEvent(MotionEvent event) { Log.d(TAG, "+ onTouchEvent(event:" + event + ")"); Log.d(TAG, "- onTouchEvent()"); return super.onTouchEvent(event); } . . . } public class GameView extends SurfaceView implements SurfaceHolder.Callback { private static final String TAG = "GameView"; . . . @Override public boolean onTouchEvent(MotionEvent event) { Log.d(TAG, "+ onTouchEvent(event:" + event + ")"); gestureDetector.onTouchEvent(event); Log.d(TAG, "- onTouchEvent()");

How can I detect tap on the screen?

一笑奈何 提交于 2019-12-05 02:49:21
More specific where do I attach OnGestureListener so that I can detect onSingleTapUp everywhere on the screen, even if an ImageView take up half the screen. Now I have the Listener on the Activity that has an ImageView. But the Listener only fire when I click outside the ImageView. I read and try to understand this but cannot get it right. this code is in the Activity. public boolean onSingleTapUp(MotionEvent e) { //addtext.setText("-" + "SINGLE TAP UP" + "-"); //Log.d(TAG, "- + SINGLE TAP UP + - ***********************************************************************"); int btnsize =

How to get GestureDetector working correctly

会有一股神秘感。 提交于 2019-12-04 15:47:59
I have this code so far in my Activity: private class SwipeGestureDetector extends SimpleOnGestureListener { // Swipe properties, you can change it to make the swipe // longer or shorter and speed private static final int SWIPE_MIN_DISTANCE = 120; private static final int SWIPE_MAX_OFF_PATH = 200; private static final int SWIPE_THRESHOLD_VELOCITY = 200; @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { float diffAbs = Math.abs(e1.getY() - e2.getY()); float diff = e1.getX() - e2.getX(); Log.d("MainDisplayActivity", "Gesture class is