Android自定义ProgressBar样式

预期效果

要实现如下的进度条的样式:
这里写图片描述

实现过程

我们对横向的进度条样式进行如下的定义:

<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_bgroundprogress_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定义为整个进度条高度的一半,这样就能保证进度条的形状是胶囊体轮廓。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值