欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

自定义View 之 圆形

程序员文章站 2022-07-13 15:39:30
...

自定义View 圆形

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

/**
 * @Auther: djYan
 * @Date: 2019/2/22 14:32:31
 * @Description:
 */
public class MyCircles extends View {

    private int measuredHeight;
    private int measuredWidth;

    public MyCircles(Context context) {
        super(context);
    }


    public MyCircles(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        measuredHeight = getMeasuredHeight();
        measuredWidth = getMeasuredWidth();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        canvas.drawCircle(measuredWidth / 2, measuredHeight / 2, 100, paint);
    }
}
相关标签: 自定义View