添加upperPaint。setXfermode(新的PorterDuffXfermode(PorterDuff.Mode.CLEAR));
public class GetsugaDrawable extends Drawable {
private final Context context;
private final float radiusScale = 1.2f;
private final float yOffset = 0.3f;
private final int colorLower = Color.RED;
private final int colorUpper = Color.BLACK;
private final Paint upperPaint = new Paint();
public GetsugaDrawable(Context c) {
context = c;
upperPaint.setAntiAlias(true);
upperPaint.setColor(colorUpper);
upperPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
}
@Override
public void draw(@NonNull Canvas canvas) {
final Rect bounds = new Rect(getBounds());
canvas.drawColor(colorLower);
final float radius = radiusScale * bounds.height();
final int x = bounds.centerX();
final float y = (bounds.centerY() - bounds.height() * yOffset) - radius;
canvas.drawCircle(x, y, radius, upperPaint);
}
@Override
public void setAlpha(int alpha) {
}
@Override
public void setColorFilter(@Nullable ColorFilter colorFilter) {
}
@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}}
不要忘记观看。setLayerType(View.LAYER\u TYPE\u HARDWARE,null);在目标视图上