Android--橫向progressbar設定與實現

來源:互聯網
上載者:User

標籤:android   progress   bar   

轉載請註明出處,謝謝~~

許多人都問這個橫向的progressbar不行啊,我只能說肯定是哪沒設定對,下面我就貼貼我的設定,僅供參考。

<ProgressBar         android:id="@+id/game_pro"        android:layout_below="@id/game_name"        android:layout_width="100dp"        android:layout_height="30dp"        android:layout_marginTop="10dp"         style="?android:attr/progressBarStyleHorizontal"        android:background="@null"        android:layout_centerHorizontal="true"        android:progressDrawable="@drawable/progress_bg"/>

忽略什麼id啊,below啊什麼的。
width和height是設定progressbar的寬高,這可以寫死,你寫多大它就多大。
style必須是這個,只有設成這個才會是橫向的。
background設定為null,這樣就不會有背景蓋住我們的背景。
然後progressDrawable 是重點,看看裡面的具體代碼:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >    <item android:id="@android:id/background">        <shape>            <corners android:radius="2dp" />            <gradient                android:angle="270"                android:centerColor="@drawable/progress_back"                android:centerY="0.75"                android:endColor="@drawable/progress_back"                android:startColor="@drawable/progress_back" />        </shape>    </item>    <!--    <item android:id="@android:id/secondaryProgress">         <clip>             <shape>                 <corners android:radius="5dip" />                 <gradient                         android:startColor="#80ffd300"                         android:centerColor="#80ffb600"                         android:centerY="0.75"                         android:endColor="#a0ffcb00"                         android:angle="270"                 />             </shape>         </clip>     </item>    -->    <item android:id="@android:id/progress">        <clip>            <shape>                <corners android:radius="2dip" />                <gradient                    android:angle="270"                    android:centerColor="@drawable/progress_forecolor"                    android:centerY="0.75"                    android:endColor="@drawable/progress_forecolor"                    android:startColor="@drawable/progress_forecolor" />            </shape>        </clip>    </item></layer-list>

第一個 item 我們可以看到是android:id=”@android:id/background”,這是沒有progress時候的背景色,這裡設定的是個灰色的16進位。然後第二個被注釋掉的item是 secondaryProgress,你懂的,有的進度條兩個顏色進度,就是這個。第三個item是progress,就是我們要顯示的第一個進度條的顏色。這樣設定之後就完全沒有問題了。貼個圖:

Android--橫向progressbar設定與實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.