<ProgressBar
android:id="@+id/progressBar_one"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_width="match_parent"
android:layout_height="30dp"
style="?android:attr/progressBarStyleHorizontal"
android:progressDrawable="@drawable/progressbar_style"
android:max="100"
android:layout_marginTop="20dp"
/>
最近项目中要求做一个横向的柱状图,没找到好的例子,就用ListView + progress 代替了,每个条目里面放置一个
代码里设置progressbar的背景色:
mProgressBar = (ProgressBar) findViewById(R.id.progressBar_one);
Drawable progressDrawable=getResources().getDrawable(R.drawable.<span style="font-family: Arial, Helvetica, sans-serif;">progressbar_style</span>);
mProgressBar.setProgressDrawable(progressDrawable);
mProgressBar.setProgress(70);
progressbar_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="6.0dip" /> <!--圆角-->
<gradient android:startColor="#f7f7f7"
android:endColor="#f7f7f7"
android:angle="270.0"
android:centerY="0.75"
android:centerColor="#f7f7f7" /> <!--渐变的背景-->
<stroke android:width="0.5dp" android:color="#7d7f83" /><!-- 描边,边框宽度、颜色 -->
</shape>
</item>
<!--第二条进度,可以不需要-->
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="6.0dip" />
<gradient android:startColor="#e71a5e"
android:endColor="#6c213a"
android:angle="90.0"
android:centerY="0.75"
android:centerColor="#ac6079" />
<stroke android:width="0.5dp" android:color="#7d7f83" />
</shape>
</clip>
</item>
<!--进度颜色-->
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="6.0dip" />
<gradient
android:startColor="#e2e4e8"
android:endColor="#e2e4e8"
android:centerColor="#e2e4e8"
android:angle="270.0" />
<stroke android:width="0.5dp" android:color="#7d7f83" />
</shape>
</clip>
</item>
</layer-list>