The full error is: java.lang.IllegalState

ImageView no longer exists. You should not use this PhotoViewAttacher any more.

The full error is:

写道
java.lang.IllegalStateException: ImageView no longer exists. You should not use this PhotoViewAttacher any more.
uk.co.senab.photoview.PhotoViewAttacher.getImageView(PhotoViewAttacher.java:209)
uk.co.senab.photoview.PhotoViewAttacher.onSingleTapConfirmed(PhotoViewAttacher.java:351)
android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:320)
 
在PhotoViewAttacher  文件中 更改cleanup方法
 参考

https://github.com/chrisbanes/PhotoView/issues/67

 

定位到找到cleanup()代码,
//
写道
@SuppressWarnings("deprecation")
// public final void cleanup() {
// if (null != mImageView) {
// mImageView.get().getViewTreeObserver().removeGlobalOnLayoutListener(this);
// }
// mViewTreeObserver = null;
//
// // Clear listeners too
// mMatrixChangeListener = null;
// mPhotoTapListener = null;
// mViewTapListener = null;
//
// // Finally, clear ImageView
// mImageView = null;
// }
 

修改成

 

 写道

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public final void cleanup() {
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN)
{
if (null != mImageView) {
mImageView.get().getViewTreeObserver().removeOnGlobalLayoutListener(this);
}

if (null != mViewTreeObserver && mViewTreeObserver.isAlive()) {
mViewTreeObserver.removeOnGlobalLayoutListener(this);

mViewTreeObserver = null;

// Clear listeners too
mMatrixChangeListener = null;
mPhotoTapListener = null;
mViewTapListener = null;
// Finally, clear ImageView
mImageView = null;
}

}
else
{
if (null != mImageView) {
mImageView.get().getViewTreeObserver().removeGlobalOnLayoutListener(this);
}

if (null != mViewTreeObserver && mViewTreeObserver.isAlive()) {
mViewTreeObserver.removeGlobalOnLayoutListener(this);

mViewTreeObserver = null;

// Clear listeners too
mMatrixChangeListener = null;
mPhotoTapListener = null;
mViewTapListener = null;
// Finally, clear ImageView
mImageView = null;
}
}
}
 

你可能感兴趣的:(photoview)