onFling和SimpleOnGestureListener麻烦

|| 我正在实现一个onFling检测器,类似于以下问题: 网格布局上的翻转手势检测 但是,我只是无法使其正常工作。 如果我通过某种方式设置了我的应用程序而导致了这个问题(也许是asynctask?),则这是我的应用程序的结构: (试图使它成为格式正确的列表,但是由于某种原因,它搞砸了下面的代码?) --MapActivity创建一个MapView。 --MapView创建ASyncTask以从URL提取XML。 ASyncTask的--onPostExecute()解析XML并使用获取的数据添加ItemizedOverlay ItemizedOverlay的--onTap()函数使用LoaderImageView从Web上获取图像(http://www.anddev.org/novice-tutorials-f8/imageview-with-loading-spinner-t49439.html) --onTap()函数然后调用下面列出的PopupPanel类的show()函数 从下面的代码中可以看到,注释行有效。但是,与MyGestureDetector类一起使用时,永远不会触发onTouch和onFling事件。
class PopupPanel {
    View popup;
    boolean isVisible = false;
    private static final int SWIPE_MIN_DISTANCE = 120;
    private static final int SWIPE_MAX_OFF_PATH = 250;
    private static final int SWIPE_THRESHOLD_VELOCITY = 200;
    private GestureDetector gestureDetector;
    public View.OnTouchListener gestureListener;

    PopupPanel(Context context, int layout) {
        ViewGroup parent = (ViewGroup) map.getParent();

        popup = ((MapActivity) context).getLayoutInflater().inflate(layout, parent, false);

        SelectFilterActivity selectFilterActivity = new SelectFilterActivity();
        popup.setOnClickListener(selectFilterActivity);

// This works!
//            popup.setOnTouchListener(new View.OnTouchListener() {
//                public boolean onTouch(View v, MotionEvent event) {
//                    Toast.makeText(map.getContext(), \"Touched\", Toast.LENGTH_SHORT).show();
//                    return false;
//                }
//            });

        // Gesture detection
        gestureDetector = new GestureDetector(new MyGestureDetector());
        gestureListener = new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                if (gestureDetector.onTouchEvent(event)) {
                    return true;
                }
                return false;
            }
        };
    }

    class MyGestureDetector extends SimpleOnGestureListener {
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            try {
                if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
                    return false;
                // right to left swipe
                if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                    Toast.makeText(map.getContext(), \"Left Swipe\", Toast.LENGTH_SHORT).show();
                }  else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                    Toast.makeText(map.getContext(), \"Right Swipe\", Toast.LENGTH_SHORT).show();
                }
            } catch (Exception e) {
                // nothing
            }
            return false;
        }

        @Override
        public boolean onDown(MotionEvent e) {
            return true;
        }
    }

    View getView() {
        return (popup);
    }

    void show(boolean alignTop) {
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);

        if (alignTop) {
            lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            lp.setMargins(0, 20, 0, 0);
        } else {
            lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            lp.setMargins(0, 0, 0, 60);
        }

        hide();

        ((ViewGroup) map.getParent()).addView(popup, lp);
        isVisible = true;
    }

    void hide() {
        if (isVisible) {
            isVisible = false;
            ((ViewGroup) popup.getParent()).removeView(popup);
        }
    }
}
    
已邀请:
我不确定这是否是100%的原因,但是我看不到手势侦听器代码中对View.setOnTouchListener的调用。我本来期望的;
setOnTouchListener(gestureListener)
创建它之后。     
尝试从
MyGestureDetector.onDown
中退还
true
。超类的实现是返回“ 4”,然后抑制将来事件的传递,直到释放触摸为止。     

要回复问题请先登录注册