java.lang.IllegalStateException: ImageView no longer exists. You should not use this PhotoViewAttacher any more.
这个错误今天碰到了,下面是解决方法,直接上代码
在PhotoViewAttacher 文件中 更改cleanup方法
发现可行
1 /* 2 * @SuppressWarnings("deprecation") 3 * public final void cleanup() { 4 * if (null!= mImageView) { 5 * mImageView.get().getViewTreeObserver().removeGlobalOnLayoutListener(this); 6 * } 7 * mViewTreeObserver = null; 8 * 9 * // Clear 10 * listeners too mMatrixChangeListener = null; 11 * mPhotoTapListener = null; 12 * mViewTapListener = null; 13 * 14 * // Finally, clear ImageView 15 * mImageView = null; } 16 */ 17 @SuppressWarnings("deprecation") 18 public final void cleanup() { 19 if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) { 20 if (null != mImageView) { 21 mImageView.get().getViewTreeObserver() 22 .removeOnGlobalLayoutListener(this); 23 } 24 25 if (null != mViewTreeObserver && mViewTreeObserver.isAlive()) { 26 mViewTreeObserver.removeOnGlobalLayoutListener(this); 27 28 mViewTreeObserver = null; 29 30 // Clear listeners too 31 mMatrixChangeListener = null; 32 mPhotoTapListener = null; 33 mViewTapListener = null; 34 // Finally, clear ImageView 35 mImageView = null; 36 } 37 38 } else { 39 if (null != mImageView) { 40 mImageView.get().getViewTreeObserver() 41 .removeGlobalOnLayoutListener(this); 42 } 43 44 if (null != mViewTreeObserver && mViewTreeObserver.isAlive()) { 45 mViewTreeObserver.removeGlobalOnLayoutListener(this); 46 47 mViewTreeObserver = null; 48 49 // Clear listeners too 50 mMatrixChangeListener = null; 51 mPhotoTapListener = null; 52 mViewTapListener = null; 53 // Finally, clear ImageView 54 mImageView = null; 55 } 56 } 57 }