Android: 同时使用 GestureDetector 和 Zoomy

Android: Use GestureDetector and Zoomy at the same time

我在图像上使用 GestureListener 来检测双击。

            holder.image.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return holder.myDoubleTapDetector.onTouchEvent(event);
                }
            });

我使用库 Zoomy 使图像可缩放。

            Zoomy.Builder builder = new Zoomy.Builder(mActivity).target(holder.image);
            builder.register();

两者单独使用都很好。

但是同时添加两者 行不通!只有最后添加的才有效。

我怎样才能让他们都工作?

Zoomy 提供了一个解决方案:

Because Zoomy works by attaching a View.OnTouchListener to the registered View, View.OnClickListener can not be set along with Zoomy, so a TapListener, LongPressListener and DoubleTapListener are provided to ensure the View still can listen for gestures. A ZoomListener is also provided if you are interested in zoom events.

在代码中:

Zoomy.Builder builder = new Zoomy.Builder(this)
                    .target(mZoomableView)
                    .tapListener(new TapListener() {
                        @Override
                        public void onTap(View v) {
                            //View tapped, do stuff
                        }
                    })
                     .longPressListener(new LongPressListener() {
                        @Override
                        public void onLongPress(View v) {
                            //View long pressed, do stuff
                        }
                    }).doubleTapListener(new DoubleTapListener() {
                        @Override
                        public void onDoubleTap(View v) {
                            //View double tapped, do stuff
                        }
                    })
                    .zoomListener(new ZoomListener() {
                        @Override
                        public void onViewStartedZooming(View view) {
                            //View started zooming
                        }

                        @Override
                        public void onViewEndedZooming(View view) {
                            //View ended zooming
                        }
                    });