PhotoView
PhotoView copied to clipboard
Bad works with viewpager2
But the problems are that of alpha02 and above ViewPager2, he now final class
Same here. The inital page is always blank. The photo isn't displayed. THat also happens with the original ImageView, but there, at least, it works when calling notifyDatasetChanged after 1000ms (just a test).
Also moving the photo when zoomed in doesn't work, since the scroll interception of viewpager2 takes place.
did you guys solve this problem? need somehow to disable viewpager interactions until image scrolled to the side edge
Nope, I'm still using the original vewpager
I have the same problem
<---?xml version="1.0" encoding="utf-8"?-->
<---LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:gravity="center">
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/pvPhotoView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<--/LinearLayout-->
try this...
A simple fix on incorrect zoom behavior. The problem is at PhotoViewAttacher.java line 101
if (mScaleDragDetector.isScaling()) {
return; // Do not drag if we are already scaling
}
When user doing multi touch, mScaleDragDetector.isScaling()
may return false
, and when zoom gesture occurs on edge.
line 120 allow parent view to intercept touch event.
if (mAllowParentInterceptOnEdge && !mScaleDragDetector.isScaling() && !mBlockParentIntercept) {
if (mHorizontalScrollEdge == HORIZONTAL_EDGE_BOTH
|| (mHorizontalScrollEdge == HORIZONTAL_EDGE_LEFT && dx >= 1f)
|| (mHorizontalScrollEdge == HORIZONTAL_EDGE_RIGHT && dx <= -1f)
|| (mVerticalScrollEdge == VERTICAL_EDGE_TOP && dy >= 1f)
|| (mVerticalScrollEdge == VERTICAL_EDGE_BOTTOM && dy <= -1f)) {
if (parent != null) {
parent.requestDisallowInterceptTouchEvent(false);
}
}
}
FIX (Not changing the original library code)
Wrapping PhotoView with a custom PhotoViewWrapper, which redo requestDisallowInterceptTouchEvent
after PhotoView wrongly allowing parent view's interception.
PhotoViewWrapper.kt:
class PhotoViewWrapper(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) {
private var isParentInterceptionDisallowed = false
override fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {
isParentInterceptionDisallowed = disallowIntercept
if (disallowIntercept) {
// PhotoView wants to disallow parent interception, let it be.
parent.requestDisallowInterceptTouchEvent(disallowIntercept) // don't ban wrapper itself
}
else {
// PhotoView wants to allow parent interception, we need to re-check it.
}
}
override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
// always false when up or cancel event,
// which will allow parent interception normally.
val isMultiTouch = ev.pointerCount > 1
// re-check if it's multi touch
parent.requestDisallowInterceptTouchEvent(
isParentInterceptionDisallowed || isMultiTouch
)
return false
}
}
layout.xml
<your.view.PhotoViewWrapper
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
>
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
/>
</your.view.PhotoViewWrapper>
Also can change the source code:
- Modify the
OnGestureListener.onDrag
function, AddisMultiTouch
interface OnGestureListener {
void onDrag(boolean isMultiTouch, float dx, float dy);
- Modify the
PhotoViewAttacher
at line 126
if (parent != null && !isMultiTouch) {
parent.requestDisallowInterceptTouchEvent(false);
}
- Finally,modify
CustomGestureDetector
at line 150
mListener.onDrag(ev.getPointerCount() > 1, dx, dy);