自定义View绘制简单的圆环的实现

package com.loaderman.mywave;

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

/**
 *
 * 绘制简单圆环
 */
public class SimpleRing extends View {
    private Paint paint;
    public SimpleRing(Context context) {
        this(context, null);
    }
    public SimpleRing(Context context, AttributeSet attrs) {
        this(context, attrs, -1);
    }
    public SimpleRing(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }
    private void init() {
        paint = new Paint();
        paint.setColor(Color.RED);
        paint.setStyle(Paint.Style.STROKE);//空心
        paint.setStrokeWidth(10);//设置圆环宽度
        paint.setAntiAlias(true);//去掉锯齿
    }
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //绘制圆环: 参1,2: 圆心坐标; 参3:半径
        canvas.drawCircle(getWidth() / 2, getHeight() / 2, 100, paint);
    }
}

 效果图:

posted on 2017-03-07 14:47  LoaderMan  阅读(173)  评论(0编辑  收藏  举报

导航