Android 設置進度條背景


Android 設置進度條背景

直接上代碼

<ProgressBar
            android:id="@+id/progressBar"
            android:layout_width="match_parent"
            android:layout_height="20dp"
            android:layout_gravity="center_horizontal"
            android:indeterminateOnly="false"
            android:max="100"
            android:progress="10"
            android:progressDrawable="@drawable/my_progress_horizontal" />
drawable設置
<?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="0dip" />

            <gradient
                android:angle="0"
                android:centerColor="#E6E6E6"
                android:endColor="#E6E6E6"
                android:startColor="#E6E6E6" />
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="0dip" />

                <gradient
                    android:angle="0"
                    android:centerColor="#49BCFF"
                    android:endColor="#49BCFF"
                    android:startColor="#49BCFF" />
            </shape>
        </clip>
    </item>

</layer-list>

shape是用來定義形狀的,gradient定義該形狀里面為漸變色填充,startColor起始顏色,endColor結束顏色,angle表示方向角度。當angle=0時,漸變色是從左向右。 然后逆時針方向轉,當angle=90時為從下往上。

android:shape 配置的是圖形的形式,主要包括方形、圓形等,上邊代碼為方形。gradient節點主要配置起點顏色、終點顏色、中間點的坐標、中間點的顏色、漸變角度(90度為上下漸變,0為左右漸變),padding節點主要配置上下左右邊距,corners節點配置四周園角的半徑

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM