自绘控件
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
/**
* author:Created by WangZhiQiang on 2017/11/3.
*/
public class MyView extends View {
public MyView(Context context) {
super(context);
}
public MyView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public MyView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
/**
* 自定义View最重要的方法
* @param canvas 画布
*/
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Paint.Style.STROKE);//无填充
paint.setColor(Color.BLUE);//画笔颜色
paint.setFakeBoldText(true);//画笔粗
//单位是px像素
canvas.drawCircle(DensityUtil.dip2px(getContext(),50),DensityUtil.dip2px(getContext(),50),DensityUtil.dip2px(getContext(),50),paint);
}
}