之前设置的都是在布局XML文件配置的,要想从代码角度来动态设置还需要我们进行一些改造如下:
设置路程数量及文字资源
public void setStepTextContent(@NonNull List<String> paramList) {
this.stepCount = paramList.size();
if (stepCount < 2) {
throw new IllegalArgumentException("参数长度异常,长度至少为2");
}
stepTextContent.clear();
stepTextLength.clear();
this.stepTextContent.addAll(paramList);
for (int i = 0; i < stepCount; i++) {
stepTextLength.add(mTextPaint.measureText(stepTextContent.get(i)));
}
postInvalidate();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
更改设置当前流程方法:
public void setStep(int step) {
if (step > stepCount || step < 0) {
throw new IllegalArgumentException("超出步骤范围");
}
this.step = step;
postInvalidate(http://www.amjmh.com/v/);
}
---------------------