欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android自定义ProgressBar写法

程序员文章站 2022-03-15 10:34:10
效果预览

效果预览
Android自定义ProgressBar写法

<ProgressBar
            android:id="@+id/progressBar"
            app:layout_constraintTop_toBottomOf="@id/layout_clock_logo"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginTop="30dp"
            android:layout_width="@dimen/progress_bar_width"
            android:layout_height="wrap_content"
            android:max="100"
            android:progress="15"
            style="@style/MyProgressBar"/>
 <style name="MyProgressBar" parent="@android:style/Widget.ProgressBar.Horizontal">
        <item name="android:maxHeight">20dip</item>
        <item name="android:minHeight">15dip</item>
        <item name="android:indeterminateOnly">false</item>
        <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
        <item name="android:progressDrawable">@drawable/progressbar_h1</item>
</style>

progressbar_h1.xml

<?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="20dp" />
            <stroke
                android:width="1dp"
                android:color="#ffffff" />
            <gradient
                android:angle="0"
                android:endColor="@color/transparent"
                android:startColor="@color/transparent" />
            <padding
                android:bottom="3dp"
                android:left="3dp"
                android:right="3dp"
                android:top="3dp" />
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <scale
                android:drawable="@drawable/progressbar_h_shape1"
                android:scaleWidth="100%" />
        </clip>
    </item>
</layer-list>

progressbar_h_shape1.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <corners android:radius="20dp" />
    <gradient
        android:angle="0"
        android:endColor="@color/progress_color"
        android:startColor="@color/progress_color" />

</shape>

本文地址:https://blog.csdn.net/lujianfeiccie2009/article/details/108864261