学习:
自定义控件三部曲之绘图篇(十)——Paint之setXfermode(一)
实践
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(Color.WHITE, PorterDuff.Mode.CLEAR);
Paint paint = new Paint();
paint.setColor(Color.WHITE);
int layerID = canvas.saveLayer(0,0,getWidth(),getHeight(),paint,Canvas.ALL_SAVE_FLAG);
canvas.drawRect(0,radius,getWidth(),getHeight(),paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OVER));
canvas.drawOval(new RectF((getWidth()/2) - radius, 0, (getWidth()/2)+radius, radius*2), paint);
paint.setXfermode(null);
canvas.restoreToCount(layerID);
}
比canvas.clipPath那种不用自己描线画图形了,锯齿更少,但是渲染多了