Reprint please indicate the source: http://blog.csdn.net/qq_32059827/article/details/52203533 Click to open the link
In the Android beginner tutorial, the theoretical knowledge of shape usage is introduced, and it will be very simple to complete this small case. (Welcome to learn to read): http://blog.csdn.net/qq_32059827/article/details/52203347 Click to open the link
This article is for this knowledge point, complete a custom color progress bar. The system comes with the ring progress bar is black and white, if you are not color blindness, it must feel that the progress bar is ugly! It is necessary to design its state, let us give her some "color" look.
First look at the design of the progress bar looks like, dynamic as follows:
The next step is to complete this effect.
As usual, build a shape-type file in the drawable directory. The inside code is as follows:
Add the following code to the 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 >
The code in the Shape,drawable/progressstyleshape.xml file is introduced into the style as follows:
<?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= ">" <!--Package One Animation 0~360° rotation, Anchor Point in center--<shape xmlns:android= "Http://schemas.android.com/apk/res/android" Android oid:innerradiusratio= "3" android:shape= "Ring" android:thicknessratio= "android:uselevel=" false "&G T <gradient android:endcolor= "#0000ff" android:startcolor= "#ff0000" android:type= "Sweep" /> <!--android:shape= "ring" system default rectangle, modified here to ring android:innerradiusratio= "" means the inner radius ratio: radius/ratio, the larger the value of the ring, the more thin outer ring of Android oid:thicknessratio= "10" means that the thickness ratio android:uselevel= "false" means that the progress bar ring does not slice, fully display gradint color gradient android:type= "sweep" means the effect of fire- </shape></rotate>
Then the layout file introduces the style:
<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>
To run the program:
Android Simple Combat Tutorial--the 17th session of the Custom color loop progress bar