- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
您好,SimpleOnGestureListener 在我的应用程序中不起作用,这就是我实现它的方式。也许您可以发现问题所在。调试显示应用程序永远不会进入 onFling(...) 方法和 gdt.onTouchEvent(event);总是返回错误:/有任何想法吗??谢谢
我的 Activity 课
public class SimpleActivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simpleLayout);
final ImageView imageView = (ImageView) findViewById(R.id.gggbbb);
imageView.setOnTouchListener(new OnFlingGestureListener() {
@Override
public void onTopToBottom() {
System.out.println("top");
}
@Override
public void onRightToLeft() {
System.out.println("right");
}
@Override
public void onLeftToRight() {
System.out.println("left");
}
@Override
public void onBottomToTop() {
System.out.println("bottom");
}
});
}
}
我的抽象监听器
package com.dmd.client.detailsMenus;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
public abstract class OnFlingGestureListener implements OnTouchListener {
private final GestureDetector gdt = new GestureDetector(new GestureListener());
@Override
public boolean onTouch(final View v, final MotionEvent event) {
return gdt.onTouchEvent(event);
}
private final class GestureListener extends SimpleOnGestureListener {
private static final int SWIPE_MIN_DISTANCE = 60;
private static final int SWIPE_THRESHOLD_VELOCITY = 100;
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
onRightToLeft();
return true;
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
onLeftToRight();
return true;
}
if(e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
onBottomToTop();
return true;
} else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
onTopToBottom();
return true;
}
return false;
}
}
public abstract void onRightToLeft();
public abstract void onLeftToRight();
public abstract void onBottomToTop();
public abstract void onTopToBottom();
}
最佳答案
替换此事件:
@Override
public boolean onTouch(final View v, final MotionEvent event) {
gdt.onTouchEvent(event);
return true;
}
它应该工作
关于android - SimpleOnGestureListener 永远不会进入 onFling(...) 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9313607/
我想通过在我的 MainActivity 中滑动来切换 Activity 。我从 GestureDetectorCompat 声明了一个对象,并在 onCreate 方法中对其进行了初始化,如下所示:
我的布局xml文件是这样的 我的主要 Activity 是这样的 .... gDetector = new GestureDetector(
我需要在用户从左向右滑动时更改图像;这就是为什么我使用 SimpleOnGestureListener 来检测 ImageView 上的滑动事件。 在此过程中,当我缓慢滑动图像时,onScroll()
我在这个 Android 应用程序上实现了一个 SimpleOnGestureListener,它是基本实现并且一切正常: 该类实现了 OnTouchListener,我将它设置为正确 View 的
我正在实现一个扩展 SimpleOnGestureListener 的 MyGestureDetector。我从以下类(class)借来的:http://www.codeshogun.com/blog
我有一个屏幕,其中有页眉、ScrollView 和页脚中的 TextView。我必须使用 ScrollView,因为 TextView 中的文本也可能很长。 现在,当我为此屏幕使用 SimpleOnG
我已经实现了 SimpleOnGestureListener.onFling(),但我必须非常快地挥动才能触发它。有什么办法让它更灵敏吗? 提前致谢... 最佳答案 触发 onFling() 事件所需
我创建了一个带有 onTouchListener 和手势检测器的自定义组件,我将自定义组件放在 MainActivity 的 xml 文件中,该文件还具有 onTouchEvent 和手势检测器。我想
您好,SimpleOnGestureListener 在我的应用程序中不起作用,这就是我实现它的方式。也许您可以发现问题所在。调试显示应用程序永远不会进入 onFling(...) 方法和 gdt.o
我正在实现一个 onFling 检测器,很像下面的问题: Fling gesture detection on grid layout 但是,我无法让它工作。 如果我设置我的应用程序的某种方式导致了这
我试图在一个简单的 Android 应用程序上检测一个 throw 事件,但第一个 MotionEvent 参数始终为空。为什么使用 null 参数调用 onFling 方法? Android doc
我是 Android 编程的新手,最近我将注意力转向处理简单的手势。我知道 GestureDetector 和监听器,并且我成功地实现了我需要的简单手势(onDown、onFling、onScroll
public class GameActivity extends Activity { private static final String TAG = "GameActivity";
使用这个 mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
我有如下的手势检测器类 class MyGestureListener extends GestureDetector.SimpleOnGestureListener { @Override
我正在使用 SimpleOnGestureListener检测 onSingleTapUp事件和 View 。 View 的比例因子为 5,因此 1 个屏幕像素对应于我 View 中的 5 个像素:
如果 GestureDetector.SimpleOnGestureListener 与 GestureDetector.OnGestureListener 执行相同的操作,但不需要未使用的代码,那么
public class MyActivity extends MapActivity implements LocationListener, OnClickListener { priva
我的应用需要检测简单的手势(滚动、点击、长按)和双指缩放。任何一个检测器都可以独立工作 - GestureDetector.SimpleOnGestureListener 用于点击/滚动和 Scale
我正在尝试创建动画: 用例:1. 用户向右(水平)滑动/拖动项目,项目被添加到购物篮中。如果他再次滑动,则会将一件相同的元素添加到篮子中。2. 用户向左(水平)滑动/拖动项目,项目将从购物篮中删除,如
我是一名优秀的程序员,十分优秀!