新建项目,新建DashBoardView
继承自View
实现OnGlobalLayoutListener
接口,并重写OnDraw
方法。
使用OnGlobalLayoutListener
接口需要重写onGlobalLayout
方法,在这个方法中我们将获取View的宽高。
新建如下变量:
private Context mContext;
private Paint mCirclePaint,mDegreePaint,mHourPaint,mMinPaint;
private int mViewWidth,mViewHeight;
初始化这些变量:
public void init(Context context){
mContext = context;
mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mDegreePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mHourPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mMinPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCirclePaint.setAntiAlias(true);
mCirclePaint.setStrokeWidth(5);
mCirclePaint.setStyle(Paint