Android 弧形背景

有时美工需要弧形背景

Screenshot_2019-10-25-17-57-20-805_com.qingmo.matchgo.png
代码如下:
public class ArcImageView extends AppCompatImageView {
    /*
     *弧形高度
     */
    private int mArcHeight=100;

    public ArcImageView(Context context) {
        this(context, null);
    }

    public ArcImageView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        Path path = new Path();
        path.moveTo(0, 0);
        path.lineTo(0, getHeight()-mArcHeight);
        path.quadTo(getWidth() / 2, getHeight()+mArcHeight, getWidth(), getHeight() - mArcHeight);
        path.lineTo(getWidth(), 0);
        path.close();
        canvas.clipPath(path);
        super.onDraw(canvas);
    }
}

你可能感兴趣的:(Android 弧形背景)