java.lang.IllegalStateException: The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher
This has become a really annoying problem in Fragments. It appears to be caused by shared element transitions on Lollipop, the OS's scaling transition animation must change the scale type.
I have found the same problem.Do you have solved it?
call the PhotoViewAttacher.cleanup before u calling onBackPressed or ondestory
璋㈣阿
There is another case that trigger this bug without make the ImageView inside a Fragment. We just need to remove all scale animations from Developer Options
I tried use photoViewAttacher.cleanup();
before onDestroy
and onStop
but it didn't work
Here is the complete stacktrace
FATAL EXCEPTION: main
Process: my.app.package, PID: 7614
java.lang.IllegalStateException: The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher
at uk.co.senab.photoview.PhotoViewAttacher.checkImageViewScaleType(PhotoViewAttacher.java:717)
at uk.co.senab.photoview.PhotoViewAttacher.setImageViewMatrix(PhotoViewAttacher.java:848)
at uk.co.senab.photoview.PhotoViewAttacher.resetMatrix(PhotoViewAttacher.java:840)
at uk.co.senab.photoview.PhotoViewAttacher.updateBaseMatrix(PhotoViewAttacher.java:925)
at uk.co.senab.photoview.PhotoViewAttacher.onGlobalLayout(PhotoViewAttacher.java:435)
at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:912)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1881)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
gradle import
compile 'com.github.chrisbanes:PhotoView:1.3.1'
+1 Encountering the same issue here.
I also encountered this on version 1.3.1 and I used the same workaround as with the ViewPager.
I created the following class:
public class MyPhotoViewAttacher extends PhotoViewAttacher {
public MyPhotoViewAttacher(ImageView imageView) {
super(imageView);
}
public MyPhotoViewAttacher(ImageView imageView, boolean zoomable) {
super(imageView, zoomable);
}
@Override
public void onGlobalLayout() {
try {
super.onGlobalLayout();
} catch (Exception e) {
e.printStackTrace();
}
}
}
and then just use it as I would use the original PhotoViewAttacher:
final MyPhotoViewAttacher attacher = new MyPhotoViewAttacher(imageView);
Thanks @csaba-csete-87 it worked!
Most helpful comment
I have found the same problem.Do you have solved it?