在API级别28中找不到Canvas变量 [英] Can not find Canvas variables in API Level 28
问题描述
在Android 28中找不到以下 Canvas
变量。
The following Canvas
Variables are not found in 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);
推荐答案
这些标志已在API 28中删除。请参见< a href = https://developer.android.com/sdk/api_diff/28/changes/android.graphics.Canvas rel = noreferrer>此处:
Those flags have been removed in API 28. See here:
类android.graphics.Canvas
Class android.graphics.Canvas
已删除的方法
int save(int)
Removed Methods int save(int)
已删除的字段
int CLIP_SAVE_FLAG
int CLIP_TO_LAYER_SAVE_FLAG
int FULL_COLOR_LAYER_SAVE_FLAG
int HAS_ALPHA_LAYER_SAVE_FLAG
int b $ b
Removed Fields
int CLIP_SAVE_FLAG
int CLIP_TO_LAYER_SAVE_FLAG
int FULL_COLOR_LAYER_SAVE_FLAG
int HAS_ALPHA_LAYER_SAVE_FLAG
int MATRIX_SAVE_FLAG
该方法已在API 26中弃用。请参见此处:
That method was deprecated in API 26. See here:
此方法在API级别26中已弃用。
请改用saveLayer(float,float,float,float,Paint)。
This method was deprecated in API level 26. Use saveLayer(float, float, float, float, Paint) instead.
改用什么
根据API 28的 Canvas
源代码,您使用的所有标志组合起来等于 ALL_SAVE_FLAG $的值c $ c>:
According to the Canvas
source code for API 28, the flags you use all combine to be equal to the value of 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;
来自同一源代码 Canvas#saveLayer(左,上,右,底,油漆)
默认使用 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);
}
因此,看起来您的代码等效于以下代码,您可以将其用作替换代码:
So, it looks like your code is equivalent to the following code which you can use as a replacement:
canvas.saveLayer(0, 0, getWidth(), getHeight(), null);
此版本的 saveLayer()仅在API 21+上可用。要支持较低的API级别,请使用
This version of saveLayer() is only available on API 21+. To support lower API levels, use
canvas.saveLayer(0, 0, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG);
其中 Canvas.ALL_SAVE_FLAG
与相同或以上的值。
这篇关于在API级别28中找不到Canvas变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!