自定义进度条的实现

实现类似蝉游记图片加载进度条效果

自定义进度条的实现_第1张图片

styles.xml

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

drawable folder - progressbar_gray.xml

使用layer-list 实现多图层叠加,主要是更改图层的半径和颜色等属性。

  • progress:类似播放视频播放进度

  • secondaryProgress:类似播放视频缓冲进度

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

            <gradient
                android:angle="270"
                android:centerY="0.75"
                android:endColor="#ebebeb"
                android:startColor="#ebebeb" />

            <stroke
                android:width="2px"
                android:color="#c3c3c3" />
        </shape>
    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <corners android:radius="10dip" />

                <gradient
                    android:angle="270"
                    android:centerY="0.75"
                    android:endColor="#c3c3c3"
                    android:startColor="#c3c3c3" />
            </shape>
        </clip>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="10dip" />

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

</layer-list>

如何使用:

<ProgressBar
    android:id="@+id/note_progressBar"
    style="@style/ProgressBar_Gray"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:progress="2" />


你可能感兴趣的:(自定义进度条的实现)