標籤:
轉載請註明出處:http://blog.csdn.net/qq_32059827/article/details/52203533 點擊開啟連結
在Android初級教程裡面,介紹了shape用法的理論知識,再來完成這個小案例將會變得非常簡單哦。(歡迎學習閱讀):http://blog.csdn.net/qq_32059827/article/details/52203347 點擊開啟連結
這一篇就針對這個知識點,完成一個自訂的彩色進度條。系統內建的環形進度條是黑白相間的,如果你不是色盲,肯定覺得那個進度條其醜無比!就有必要設計一下它的狀態,讓我們給她點”顏色”看看。
首先看一下要設計的進度條長什麼樣子,動態如下:
接下來就一步步的完成這個效果。
還是老樣子,在drawable目錄下建一個shape類型的檔案。裡面代碼如下:
在style裡面加入如下代碼:
<style name="ProgressBar"> <item name="android:indeterminateOnly">true</item> <item name="android:indeterminateDrawable">@drawable/progressstyleshape</item> <item name="android:indeterminateBehavior">repeat</item> <item name="android:indeterminateDuration">3500</item> <item name="android:minWidth">60dip</item> <item name="android:maxWidth">60dip</item> <item name="android:minHeight">60dip</item> <item name="android:maxHeight">60dip</item> <item name="android:mirrorForRtl">false</item> </style>
在style裡面引入了shape,drawable/progressstyleshape.xml檔案裡面的代碼如下:
<?xml version="1.0" encoding="utf-8"?><rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360" > <!-- 封裝一個動畫 0~360°旋轉、錨點位於中心 --> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:innerRadiusRatio="3" android:shape="ring" android:thicknessRatio="10" android:useLevel="false" > <gradient android:endColor="#0000ff" android:startColor="#ff0000" android:type="sweep" /> <!-- android:shape="ring"系統預設矩形,這裡修改為環形 android:innerRadiusRatio=""表示內半徑比:半徑/比值,這個值越大,環形的外環越細 android:thicknessRatio="10"表示厚度比android:useLevel="false"表示讓進度條環形不切分,完全顯示 gradint表示顏色的漸層android:type="sweep" 表示掃射的效果 --> </shape></rotate>
然後再布局檔案裡面引入樣式:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <ProgressBar android:layout_centerInParent="true" style="@style/ProgressBar" android:layout_width="wrap_content" android:layout_height="wrap_content"/></RelativeLayout>
運行程式:
Android簡易實戰教程--第十七話《自訂彩色環形進度條》