永远不会触发Android GestureDetector双击

时间:2016-05-04 07:22:40

标签: android gesturedetector

我有一个自定义DialogFragment,其中包含一个自定义ScrollView,其中包含一些图像。当用户双击时我想改变图像的缩放。我在onCreateDialog

中这样做了
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = new Dialog(getContext(), android.R.style.Theme_Black_NoTitleBar_Fullscreen);
    dialog.setContentView(R.layout.fragment_document);

    scrollViewContainer = (ObservableScrollView) dialog.findViewById(R.id.scrollViewContainer);
    mGestureDetector = new GestureDetector(getActivity(), new GestureListener());

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

    return dialog;
}

GestureListener类是

private class GestureListener extends GestureDetector.SimpleOnGestureListener {
    @Override
    public boolean onDown(MotionEvent e) {
        return true;
    }

    // event when double tap occurs
    @Override
    public boolean onDoubleTap(MotionEvent e) {
        //double tap fired.
        if (mScaleFactor != 1.f) {
            mScaleFactor = mTempScaleFactor = 1f;
        } else {
            mScaleFactor = mTempScaleFactor = 2f;
        }
        prepareForZoom(e.getX(0), e.getY(0));
        setZoom();
        return true;
    }
}

我尝试在return getActivity().onTouchEvent(event);方法或/和OnTouch中添加v.dispatchTouchEvent(event),但无效。

我提到onDown方法不时被触发。

我可以以某种方式抓住onDoubleTap事件吗?

问题解决了

我在LinearLayout添加了ScrollView,然后在setOnTouchListener添加了Layout,从而解决了这个问题。

0 个答案:

没有答案