网格布局上的翻转手势检测

自闭症网瘾萝莉.ら 提交于 2020-08-10 16:27:08

问题:

I want to get fling gesture detection working in my Android application. 我想fling手势检测工作在我的Android应用程序。

What I have is a GridLayout that contains 9 ImageView s. 我所拥有的是一个GridLayout ,其中包含9个ImageView The source can be found here: Romain Guys's Grid Layout . 可以在这里找到源: Romain Guys的Grid Layout

That file I take is from Romain Guy's Photostream application and has only been slightly adapted. 我带的那个文件来自Romain Guy的Photostream应用程序 ,只是稍作修改。

For the simple click situation I need only set the onClickListener for each ImageView I add to be the main activity which implements View.OnClickListener . 对于简单的点击情况我只需要设置onClickListener每个ImageView我添加是主要的activity ,它实现View.OnClickListener It seems infinitely more complicated to implement something that recognizes a fling . 实现识别出fling东西似乎无限复杂。 I presume this is because it may span views ? 我认为这是因为它可能跨越views

  • If my activity implements OnGestureListener I don't know how to set that as the gesture listener for the Grid or the Image views that I add. 如果我的活动实现了OnGestureListener我将不知道如何将其设置为我添加的GridImage视图的手势侦听器。

    public class SelectFilterActivity extends Activity implements View.OnClickListener, OnGestureListener { ...
  • If my activity implements OnTouchListener then I have no onFling method to override (it has two events as parameters allowing me to determine if the fling was noteworthy). 如果我的活动实现了OnTouchListener那么我就没有要override onFling方法(它有两个事件作为参数,使我可以确定onFling是否值得关注)。

    public class SelectFilterActivity extends Activity implements View.OnClickListener, OnTouchListener { ...
  • If I make a custom View , like GestureImageView that extends ImageView I don't know how to tell the activity that a fling has occurred from the view. 如果我做一个自定义的View ,如GestureImageView扩展ImageView ,我不知道怎么跟一个活动fling已经从视图中发生。 In any case, I tried this and the methods weren't called when I touched the screen. 无论如何,我都尝试过这种方法,并且触摸屏幕时不会调用这些方法。

I really just need a concrete example of this working across views. 我真的只需要一个跨视图工作的具体示例。 What, when and how should I attach this listener ? 什么,何时以及如何附加此listener I need to be able to detect single clicks also. 我还需要能够检测到单击。

// Gesture detection
mGestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {

    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        int dx = (int) (e2.getX() - e1.getX());
        // don't accept the fling if it's too short
        // as it may conflict with a button push
        if (Math.abs(dx) > MAJOR_MOVE && Math.abs(velocityX) > Math.absvelocityY)) {
            if (velocityX > 0) {
                moveRight();
            } else {
                moveLeft();
            }
            return true;
        } else {
            return false;
        }
    }
});

Is it possible to lay a transparent view over the top of my screen to capture flings? 是否可以在屏幕上方放置透明视图以捕获抓拍?

If I choose not to inflate my child image views from XML can I pass the GestureDetector as a constructor parameter to a new subclass of ImageView that I create? 如果我选择不inflate从XML我的孩子形象的意见我可以传递GestureDetector作为构造函数参数的一个新的子类ImageView ,我创造?

This is the very simple activity that I'm trying to get the fling detection to work for: SelectFilterActivity (Adapted from photostream) . 这是一个非常简单的活动,我正在尝试使fling检测起作用: SelectFilterActivity(从photostream改编而成)

I've been looking at these sources: 我一直在寻找这些来源:

Nothing has worked for me so far and I was hoping for some pointers. 到目前为止,对我来说什么都没有奏效,我一直希望有一些指点。


解决方案:

参考一: https://stackoom.com/question/3vpx/网格布局上的翻转手势检测
参考二: https://oldbug.net/q/3vpx/Fling-gesture-detection-on-grid-layout
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!