我有一个自定义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
,从而解决了这个问题。