预期效果
要实现如下的进度条的样式:
实现过程
我们对横向的进度条样式进行如下的定义:
<style name="HorizontalPrgressBarStyle" parent="@android:style/Widget.ProgressBar.Horizontal" >
<item name="android:background">@null</item>
<item name="android:progressDrawable">@drawable/progress</item>
</style>
其中用到的作为progressDrawable
的图像资源文件progress.xml
定义为:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background" android:drawable="@drawable/progress_bground" />
<item android:id="@android:id/progress">
<clip android:drawable="@drawable/progress_fground" />
</item>
</layer-list>
Drawable资源progress_bground
、progress_fground
分别定义为:
progress_bground.xml
:
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="@dimen/radius_progress" />
<solid android:color="@color/holobor_gray" />
</shape>
progress_fground.xml
:
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="@dimen/radius_progress" />
<solid android:color="@color/holobor_blue" />
</shape>
用到的颜色资源的定义:
<color name="holobor_gray">#ffafafaf</color>
<color name="holobor_blue">#ff43b3ff</color>
其中用到的尺寸
@dimen/radius_progress
定义为整个进度条高度的一半,这样就能保证进度条的形状是胶囊体轮廓。