最近发现挺多应用使用了这种效果(比如爱奇艺的tv投屏按钮):
核心就是通过 PorterDuffXfermode (随便一搜就有好多好文章介绍)实现,看明白了这个图片混合原理就相当简单了。
我是自定义了一个SpreadView:
public class SpreadView extends View {
private Context context;
private Bitmap maskBitmap;
private Paint paint;
private PorterDuffXfermode porterDuffXfermode;
private Paint edgePaint;
private float progress;
private float cx, cy;
private int length;
public SpreadView(Context context, Bitmap bitmap) {
super(context);
init(context);
/*
* maskView 需要 measure 之后才能使用 maskView.draw(canvas)
* */
this.maskBitmap = bitmap;
}
private void init(Context context) {
this.context = context;
edgePaint = new Paint();
edgePaint.setColor(Color.WHITE);
edgePaint.setStyle(Paint.Style.STROKE);
edgePaint.setStrokeWidth(0);
edgePaint.setAlpha(100);
paint = new Paint();
paint.setAntiAlias(true);
porterDuffXfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
private void setProgress(float progress) {
this.progress = progress;
invalidate();
}
public void startAnim(float cx, float cy, int length) {
this.cx = cx;
this.cy = cy;
this.length = lengt