<ProgressBar
android:id="@+id/mProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_above="@id/rl_text"
android:layout_marginLeft="@dimen/padding_big"
android:layout_marginRight="@dimen/padding_big"
android:max="100"
android:progress="0"
android:progressDrawable="@drawable/pb_progress" />
可以从style的父类中得到
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 进度条背景色 -->
<item android:id="@android:id/background">
<shape>
<corners android:radius="6dp" />
<solid android:color="#f3dfc6" />
</shape>
</item>
<!-- 第二进度条 -->
<item android:id="@android:id/secondaryProgress">
<clip><!-- 内外都为圆角 替换<scale android:scaleWidth="100%"> ... </scale> -->
<shape>
<corners android:radius="6dp" />
<solid android:color="#f3dfc6" />
</shape>
</clip>
</item>
<!-- 第一进度条 -->
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="6dp" />
<solid android:color="#ffffff" />
</shape>
</clip>
</item>
</layer-list>
mProgressBar.setMax(max);
mProgressBar.setProgress(data.myPoint);
//文字
for (int i = 0; i < pointList.size(); i++) {
String point = String.valueOf(pointList.get(i));
TextView tv = new TextView(mActivity);
tv.setText(point);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(-2, -2);
params.addRule(RelativeLayout.CENTER_VERTICAL);
if (i == 0) {
//第一个
} else if (i == pointList.size() - 1) {
//最后一个
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
} else {
//每一份的宽度(这里需要精确计算 避免结果为0)
int width = mProgressBar.getWidth();
BigDecimal bi1 = new BigDecimal(width + "");
BigDecimal bi2 = new BigDecimal(max + "");
BigDecimal divide = bi1.divide(bi2, 10, BigDecimal.ROUND_HALF_UP);
//计算偏移量
double margin = divide.doubleValue() * pointList.get(i);
params.setMargins((int) margin, 0, 0, 0);
}
rl_text.addView(tv, params);
}