android上继承view实现自定义线性流程图
首次编写技术博客,有不足之处敬请谅解!
功能介绍
自定义线性流程图,实现流程调整后定位到具体流程坐标,并将对应
流程高亮显示,可以自定义修改流程中的圆、线、文字的属性如颜色、尺寸等。
示例图片
源码
public class MyProgress extends View {
private final String TAG = this.getClass().getSimpleName();
private final boolean needLog = true;
/**流程有几个步骤*/
private int STEP = 4;
/**圆直径在每步流程长度的占比*/
private float PROPORTION = 4f;
/**计算出的圆心集合*/
private PointF[] circleCenters;
/**圆直径/dp*/
private int diameter = -1;
/**圆边缘的厚度*/
private int THICKNESS = 3;
/**顶部间隔*/
private int pandingTop = 0;
/**底部间隔*/
private int pandingBottom = 0;
private Context mContext;
private Paint mPaintCircle;
private Paint mPaintLines;
private Paint mPaintText;
private int circleColor = Color.parseColor("#55A461");
private int lineColor = Color.GRAY;
private int textColor = Color.parseColor("#55A461");
private int textColorProgress = Color.GREEN;
private int mTextSize = 40;
private int mProgress = -1;
public MyProgress(Context context) {
this(context,null);
}
public MyProgress(Context context, AttributeSet attrs) {
this(context, attrs,0);
}
public MyProgress(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mContext = context;
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MyProgress, defStyleAttr, R.style.TextAppearance_AppCompat);
circleColor = typedArray.getColor(R.styleable.MyProgress_defaultColor3, circleColor);
lineColor = typedArray.getColor(R.styleable.MyProgress_progressColor3, lineColor);
/*比例*/
PROPORTION = typedArray.getFloat(R.styleable.MyProgress_proportion, PROPORTION);
STEP = typedArray.getInteger(R.styleable.MyProgress_steps, STEP);
pandingTop = typedArray.getInteger(R.styleable.MyProgress_pandingVertical, pandingTop);
initPaint();
typedArray.recycle();
}
private void initPaint() {
//灰圆形
mPaintCircle = new Paint();
mPaintCircle.setColor(circleColor);
mPaintCircle.setDither(true);
mPaintCircle.s