CustomView - 清除 canvas 感谢 setImageResource 0

CustomView - Clear canvas thanks to setImageResource 0

我试图以编程方式清除 custom ImageView 的当前图像,在我调用方法 setImageResource() 之后,我的自定义图像视图保留了旧图像。我尝试了以下解决方案:

这是我视图的 onDraw 方法:

private void loadBitmap() {
    BitmapDrawable bitmapDrawable = (BitmapDrawable) getDrawable();
    image = (bitmapDrawable != null) ? bitmapDrawable.getBitmap() : null;
}


@Override
public void onDraw(Canvas canvas) {
    loadBitmap();
    final int circleCenter = getHeight() / 2;
    final int radius = circleCenter - 5;

    if (image != null) {
        paint.setShader(computeBitmapShader());
        canvas.drawCircle(circleCenter, circleCenter, radius, paint);
    } else {
        super.onDraw(canvas);
    }
}

我犯了一个愚蠢的错误。我正在使用一个动画,其中一个视图应该出现在我的 CircleView 上,然后消失,但是 setFillAfter false 不起作用...