在Canvas
下,在Android 28中找不到变量。
canvas.saveLayer(0, 0, getWidth(), getHeight(), null,
Canvas.MATRIX_SAVE_FLAG |
Canvas.CLIP_SAVE_FLAG |
Canvas.HAS_ALPHA_LAYER_SAVE_FLAG |
Canvas.FULL_COLOR_LAYER_SAVE_FLAG |
Canvas.CLIP_TO_LAYER_SAVE_FLAG);
答案 0 :(得分:6)
这些标志已在API 28中删除。请参见here:
android.graphics.Canvas类
删除的方法 int save(int)
已删除的字段 诠释CLIP_SAVE_FLAG
诠释CLIP_TO_LAYER_SAVE_FLAG
int FULL_COLOR_LAYER_SAVE_FLAG
诠释HAS_ALPHA_LAYER_SAVE_FLAG
int MATRIX_SAVE_FLAG
该方法已在API 26中弃用。请参见here:
此方法在API级别26中已弃用。 请使用saveLayer(float,float,float,float,Paint)。
代替什么
根据API 28的Canvas
源代码,您使用的所有标志均合并为等于ALL_SAVE_FLAG
的值:
public static final int ALL_SAVE_FLAG = 0x1F;
public static final int MATRIX_SAVE_FLAG = 0x01;
public static final int CLIP_SAVE_FLAG = 0x02;
public static final int HAS_ALPHA_LAYER_SAVE_FLAG = 0x04;
public static final int FULL_COLOR_LAYER_SAVE_FLAG = 0x08;
public static final int CLIP_TO_LAYER_SAVE_FLAG = 0x10;
从同一source code到Canvas#saveLayer(left, top, right, bottom, paint)
的呼叫默认使用ALL_SAVE_FLAG
:
/**
* Convenience for {@link #saveLayer(RectF, Paint)} that takes the four float coordinates of the
* bounds rectangle. */
public int saveLayer(float left, float top, float right, float bottom, @Nullable Paint paint) {
return saveLayer(left, top, right, bottom, paint, ALL_SAVE_FLAG);
}
因此,您的代码似乎等同于以下代码,您可以将其用作替换代码:
canvas.saveLayer(0, 0, getWidth(), getHeight(), null);
答案 1 :(得分:0)
您可以使用canvas.save();而不是canvas.save(Canvas.MATRIX_SAVE_FLAG | CLIP_SAVE_FLAG) 参考