PhotoView icon indicating copy to clipboard operation
PhotoView copied to clipboard

The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher

Open afollestad opened this issue 11 years ago • 7 comments

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.

afollestad avatar Dec 05 '14 05:12 afollestad

I have found the same problem.Do you have solved it?

Ulez avatar Oct 14 '16 04:10 Ulez

call the PhotoViewAttacher.cleanup before u calling onBackPressed or ondestory

maf2356 avatar Nov 05 '16 12:11 maf2356

谢谢

Ulez avatar Nov 24 '16 06:11 Ulez

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 Phone Home

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'

hendrawd avatar Dec 29 '16 06:12 hendrawd

+1 Encountering the same issue here.

sebastian-raubach avatar Feb 07 '17 16:02 sebastian-raubach

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);

csaba-csete-87 avatar Mar 01 '17 15:03 csaba-csete-87

Thanks @csaba-csete-87 it worked!

ajaykumar2017 avatar Jul 06 '20 17:07 ajaykumar2017