先上效果图
下面上代码
1.先定义属性
<resources>
<declare-styleable name="RoundIndicatorView">
<!--圆盘最大值-->
<attr name="maxNum" format="dimension|integer"/>
<!--圆盘起始角度-->
<attr name="startAngle" format="dimension|integer"/>
<!--圆盘扫过的角度-->
<attr name="sweepAngle" format="dimension|integer"/>
</declare-styleable>
</resources>
该view中用到的变量
private int radius;//内圆半径
private int mWidth;//控件的宽度
private int mHeight;//控件的高度
private Paint paint_1;//内圆画笔
private Paint paint_2;
private Paint paint_3;
private Paint paint_4;
private Paint paint_5;
private Context context;
private int maxNum;//圆盘最大值
private int startAngle;//圆盘起始角度
private int sweepAngle;//圆盘扫过的角度
private int sweepInWidth;//内圆弧宽度
private int sweepOutWidth;//外圆宽度
private String[] text ={
"较差","中等","良好","优秀","极好"};
private int[] indicatorColor = {
0xffffffff,0x00ffffff,0x99ffffff,0xffffffff};
private int currentNum = 0;
初始化自定义的属性及画笔
/**
* 初始化自定义属性
* @param attrs
*/
private void initAttrs(AttributeSet attrs){
TypedArray typedArray = context.obtainStyledAttributes(attrs,R.styleable.RoundIndicatorView);
maxNum = typedArray.getInt(R.styleable.RoundIndicatorView_maxNum,500);
startAngle = typedArray.getInt(R.styleable.RoundIndicatorView_startAngle,160);