diff --git a/photoview/src/main/java/com/github/chrisbanes/photoview/ParentScrollDirection.java b/photoview/src/main/java/com/github/chrisbanes/photoview/ParentScrollDirection.java new file mode 100644 index 00000000..d6a64f58 --- /dev/null +++ b/photoview/src/main/java/com/github/chrisbanes/photoview/ParentScrollDirection.java @@ -0,0 +1,6 @@ +package com.github.chrisbanes.photoview; + +public @interface ParentScrollDirection { + int HORIZONTAL = 0; + int VERTICAL = 1; +} \ No newline at end of file diff --git a/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoView.java b/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoView.java index 8a8ba0a7..e0615361 100644 --- a/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoView.java +++ b/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoView.java @@ -253,4 +253,8 @@ public void setOnScaleChangeListener(OnScaleChangedListener onScaleChangedListen public void setOnSingleFlingListener(OnSingleFlingListener onSingleFlingListener) { attacher.setOnSingleFlingListener(onSingleFlingListener); } + + public void setParentScrollDirection(@ParentScrollDirection int scrollDirection) { + attacher.setParentScrollDirection(scrollDirection); + } } diff --git a/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java b/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java index f8494d41..9f55916f 100644 --- a/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java +++ b/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java @@ -90,6 +90,7 @@ public class PhotoViewAttacher implements View.OnTouchListener, private FlingRunnable mCurrentFlingRunnable; private int mHorizontalScrollEdge = HORIZONTAL_EDGE_BOTH; private int mVerticalScrollEdge = VERTICAL_EDGE_BOTH; + private int mParentScrollDirection = ParentScrollDirection.HORIZONTAL; private float mBaseRotation; private boolean mZoomEnabled = true; @@ -118,9 +119,10 @@ public void onDrag(float dx, float dy) { */ ViewParent parent = mImageView.getParent(); if (mAllowParentInterceptOnEdge && !mScaleDragDetector.isScaling() && !mBlockParentIntercept) { - if (mHorizontalScrollEdge == HORIZONTAL_EDGE_BOTH + if ((mHorizontalScrollEdge == HORIZONTAL_EDGE_BOTH && mParentScrollDirection == ParentScrollDirection.HORIZONTAL) || (mHorizontalScrollEdge == HORIZONTAL_EDGE_LEFT && dx >= 1f) || (mHorizontalScrollEdge == HORIZONTAL_EDGE_RIGHT && dx <= -1f) + || (mVerticalScrollEdge == VERTICAL_EDGE_BOTH && mParentScrollDirection == ParentScrollDirection.VERTICAL) || (mVerticalScrollEdge == VERTICAL_EDGE_TOP && dy >= 1f) || (mVerticalScrollEdge == VERTICAL_EDGE_BOTTOM && dy <= -1f)) { if (parent != null) { @@ -260,6 +262,10 @@ public void setOnSingleFlingListener(OnSingleFlingListener onSingleFlingListener this.mSingleFlingListener = onSingleFlingListener; } + public void setParentScrollDirection(@ParentScrollDirection int scrollDirection) { + this.mParentScrollDirection = scrollDirection; + } + @Deprecated public boolean isZoomEnabled() { return mZoomEnabled;