Android 利用shape自定义进度条样式

转载请注明出处。付小华的移动开发微博:http://blog.csdn.net/klxh2009

很少写博客,今天来一个。先看效果图:


项目文件结构:

1、drawable

2、stytles

3、layout


一、先看layout:

<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#B4E7BA"
    android:orientation="vertical" >

    <ProgressBar
        android:id="@+id/myprogressbar"
        style="@style/style_myprogressbar"
        android:layout_width="fill_parent"
        android:layout_height="10dp"
        android:layout_margin="20dp"
        android:background="@drawable/shape_pb_bg"
        android:max="100"
        android:progress="40" />

</LinearLayout></span>


二、再看stytles:

<style name="style_myprogressbar" parent="@android:style/Widget.ProgressBar.Horizontal">
        <item name="android:maxHeight">50dip</item>
        <item name="android:minHeight">10dip</item>
        <item name="android:indeterminateOnly">false</item>
        <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
        <item name="android:progressDrawable">@drawable/shape_pb_bg</item>
    </style>

三、drawable下的shape_pb_bg:

<?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="5dip" />

            <gradient
                android:angle="270"
                android:centerY="0.75"
                android:endColor="#FFFFFF"
                android:startColor="#FFFFFF" />
        </shape>
    </item>
    <!-- 进度 -->
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="5dip" />

                <gradient
                    android:angle="270"
                    android:centerY="0.75"
                    android:endColor="#1D00FF"
                    android:startColor="#1D00FF" />
            </shape>
        </clip>
    </item>

</layer-list>

OK,有这些就够了,谢谢。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值