自定义控件(二)

实现如下的一个自定义控件,
stepview
有点类似于stepView,像物流订单信息的那种一样,如下所示

所以也参考了StepView,实现了该效果。

上下的节点个数都可以自定义,红色或者绿色的节点代表这个产品的范围,直接通过代码详细看思路。

一、初始化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
private List<StepViewBean> mStepViewBeanList;
private List<Float> mCircleCenterPointPositionList;
private Paint mUnCompletedPaint;
private Paint mCompletedPaint;
private int mUnCompletedLineColor = ContextCompat.getColor(getContext(), R.color.textColor_E0E0E0);
private int mCompletedLineColor = ContextCompat.getColor(getContext(), R.color.colorPrimary);
/**
* init
*/
private void init() {
mStepViewBeanList = new ArrayList<>();//当前有几个这样的流程,栗子中为上下红绿两个,一个StepViewBean对象代表一个流程
mCircleCenterPointPositionList = new ArrayList<>();//定义所有圆的圆心点位置的集合
mUnCompletedPaint = new Paint(); //创建画笔 (未完成)
mUnCompletedPaint.setAntiAlias(true);//设置抗锯齿
mUnCompletedPaint.setColor(mUnCompletedLineColor); //未完成的画笔颜色 e0e0e0
mUnCompletedPaint.setStyle(Paint.Style.FILL); //设置类型为填充
mUnCompletedPaint.setStrokeWidth(FontDisplayUtil.dip2px(getContext(), 2)); //设置画笔粗细
mCompletedPaint = new Paint(); //创建画笔 (完成)
mCompletedPaint.setAntiAlias(true); //设置抗锯齿
mCompletedPaint.setColor(mCompletedLineColor); //完成的画笔颜色
mCompletedPaint.setStyle(Paint.Style.FILL); //设置类型为填充
mCompletedPaint.setStrokeWidth(FontDisplayUtil.dip2px(getContext(), 2)); //设置画笔粗细
//已经完成线的宽高
mCompletedLineHeight = 0.1f * defaultStepIndicatorNum;
//圆的半径
mCircleRadius = 0.28f * defaultStepIndicatorNum;
//线与线之间的间距
mLinePadding = 2f * defaultStepIndicatorNum;
mCompleteIcon = ContextCompat.getDrawable(getContext(), R.mipmap.ic_step_red_choose);//已经完成的icon
mDefaultIcon = ContextCompat.getDrawable(getContext(), R.mipmap.ic_step_no_choose);//未完成的icon
}