我已经检查了其他问题,但找不到适合我的解决方案。
那是崩溃日志。
java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@135eeb95
at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1282)
at android.view.GLES20Canvas.drawBitmap(GLES20Canvas.java:599)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:539)
at android.view.View.getDrawableRenderNode(View.java:15867)
at android.view.View.drawBackground(View.java:15816)
at android.view.View.draw(View.java:15626)
at android.view.View.updateDisplayListIfDirty(View.java:14568)
at android.view.View.getDisplayList(View.java:14590)
at android.view.View.draw(View.java:15360)
at android.view.ViewGroup.drawChild(ViewGroup.java:3604)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3397)
at android.view.View.draw(View.java:15638)
at android.widget.FrameLayout.draw(FrameLayout.java:598)
at android.view.View.updateDisplayListIfDirty(View.java:14568)
at android.view.View.getDisplayList(View.java:14590)
at android.view.View.draw(View.java:15360)
at android.view.ViewGroup.drawChild(ViewGroup.java:3604)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3397)
at android.view.View.updateDisplayListIfDirty(View.java:14563)
at android.view.View.getDisplayList(View.java:14590)
at android.view.View.draw(View.java:15360)
at android.view.ViewGroup.drawChild(ViewGroup.java:3604)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3397)
at android.view.View.draw(View.java:15638)
at android.widget.FrameLayout.draw(FrameLayout.java:598)
at android.view.View.updateDisplayListIfDirty(View.java:14568)
at android.view.View.getDisplayList(View.java:14590)
at android.view.View.draw(View.java:15360)
at android.view.ViewGroup.drawChild(ViewGroup.java:3604)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3397)
at android.view.View.updateDisplayListIfDirty(View.java:14563)
at android.view.View.getDisplayList(View.java:14590)
at android.view.View.draw(View.java:15360)
at android.view.ViewGroup.drawChild(ViewGroup.java:3604)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3397)
at android.view.View.updateDisplayListIfDirty(View.java:14563)
at android.view.View.getDisplayList(View.java:14590)
at android.view.View.draw(View.java:15360)
at android.view.ViewGroup.drawChild(ViewGroup.java:3604)
at android.support.v7.widget.RecyclerView.drawChild(RecyclerView.java:4431)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3397)
at android.view.View.draw(View.java:15638)
at android.support.v7.widget.RecyclerView.draw(RecyclerView.java:3823)
at android.view.View.updateDisplayListIfDirty(View.java:14568)
at android.view.View.getDisplayList(View.java:14590)
at android.view.View.draw(View.java:15360)
at android.view.ViewGroup.drawChild(ViewGroup.java:3604)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3397)
at android.view.View.updateDisplayListIfDirty(View.java:14563)
at android.view.View.getDisplayList(View.java:14590)
at android.view.View.draw(View.java:15360)
at android.view.ViewGroup.drawChild(ViewGroup.java:3604)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3397)
at android.view.View.updateDisplayListIfDirty(View.java:14563)
at android.view.View.getDisplayList(View.java:14590)
at android.view.View.draw(View.java:15360)
at android.view.ViewGroup.drawChild(ViewGroup.java:3604)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3397)
at android.view.View.updateDisplayListIfDirty(View.java:14563)
at android.view.View.getDisplayList(View.java:14590)
at android.view.View.draw(View.java:15360)
at android.view.ViewGroup.drawChild(ViewGroup.java:3604)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3397)
at android.view.View.updateDisplayListIfDirty(View.java:14563)
at android.view.View.getDisplayList(View.java:14590)
at android.view.View.draw(View.java:15360)
at android.view.ViewGroup.drawChild(ViewGroup.java:3604)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3397)
at android.view.View.updateDisplayListIfDirty(View.java:14563)
at android.view.View.getDisplayList(View.java:14590)
at android.view.View.draw(View.java:15360)
at android.view.ViewGroup.drawChild(ViewGroup.java:3604)
at android.support.design.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1223)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3397)
at android.view.View.draw(View.java:15638)
at android.view.View.updateDisplayListIfDirty(View.java:14568)
at android.view.View.getDisplayList(View.java:14590)
at android.view.View.draw(View.java:15360)
at android.view.ViewGroup.drawChild(ViewGroup.java:3604)
at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:1379)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3397)
at android.view.View.draw(View.java:15638)
at android.view.View.updateDisplayListIfDirty(View.java:14568)
at android.view.View.getDisplayList(View.java:14590)
at android.view.View.draw(View.java:15360)
at android.view.ViewGroup.drawChild(ViewGroup.java:3604)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3397)
at android.view.View.updateDisplayListIfDirty(View.java:14563)
at android.view.View.getDisplayList(View.java:14590)
at android.view.View.draw(View.java:15360)
at android.view.ViewGroup.drawChild(ViewGroup.java:3604)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3397)
at android.view.View.updateDisplayListIfDirty(View.java:14563)
at android.view.View.getDisplayList(View.java:14590)
at android.view.View.draw(View.java:15360)
at android.view.ViewGroup.drawChild(ViewGroup.java:3604)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3397)
at android.view.View.updateDisplayListIfDirty(View.java:14563)
at android.view.View.getDisplayList(View.java:14590)
at android.view.View.draw(View.java:15360)
at android.view.ViewGroup.drawChild(ViewGroup.java:3604)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3397)
at android.view.View.updateDisplayListIfDirty(View.java:14563)
at android.view.View.getDisplayList(View.java:14590)
at android.view.View.draw(View.java:15360)
at android.view.ViewGroup.drawChild(ViewGroup.java:3604)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3397)
at android.view.View.draw(View.java:15638)
at android.widget.FrameLayout.draw(FrameLayout.java:598)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2945)
at android.view.View.updateDisplayListIfDirty(View.java:14568)
at android.view.View.getDisplayList(View.java:14590)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:273)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:279)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:318)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2575)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2385)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2012)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1073)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5988)
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:5910)
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:1405)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
当我尝试快速从RecyclerView
删除一些项目,然后转到另一个视图,然后再次返回到RecyclerView时,会出现问题。在RecyclerView.Adapter中,我尝试使用此代码加载图像(在适配器onBindViewHolder
函数中)
Glide.with(mContext).load(imageUrl).asBitmap().centerCrop().into(new BitmapImageViewTarget(holder.mNetworkImageView)
{
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable)
{
super.onLoadFailed(e, errorDrawable);
Logger.e(e);
}
@Override
protected void setResource(Bitmap resource)
{
holder.stopSpecialAnimation();
if(!resource.isRecycled())
{
Drawable d = new BitmapDrawable(mContext.getResources(), resource);
holder.mNetworkImageView.setBackground(d);
}
}
});
如果有帮助,我也有ImageView scaleType CenterCrop。在尝试使用Glide加载图像之前,我也开始动画。我根本不会在代码中的任何位图上调用recycle()
。
我不明白导致这个问题的原因。