Android Custom level and circle ProgressBar only define some style to

Source: Internet
Author: User

:



Modify ProgressBar let him meet his needs. In general, just modify the ProgressBar style to meet the requirements:

Activity code: Show only one layout

Package Com.example.testcustomprogressbar;import Android.app.activity;import Android.os.bundle;import Android.view.menu;import Android.view.menuitem;public class Mainactivity extends Activity {@Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main);}}

XML interface:

<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        = "Com.example.testcustomprogressbar.MainActivity" > <progressbar android:id= "@+id/my_customprogressbar1" style= "@style/mycustom_progressbar1" android:layout_width= "wrap_content" android:layout_height= "Wrap_c         Ontent "android:layout_alignparenttop=" true "android:layout_centerhorizontal=" true "/> <progressbar Android:id= "@+id/my_customprogressbar2" style= "@style/mycustom_progressbar2" Android:layout_width= "W        Rap_content "android:layout_height=" wrap_content "android:layout_alignleft=" @+id/my_customprogressbar1 "        android:layout_below= "@+id/my_customprogressbar1" android:layout_margintop= "26DP"/> <ProgressBar    Android:id= "@+id/my_customprogressbar3"    style= "@style/mycustom_progressbar3" android:layout_width= "wrap_content" android:layout_height= "Wrap_con Tent "android:layout_alignleft=" @+id/my_customprogressbar2 "android:layout_below=" @+id/my_customprogressbar2        "android:layout_margintop=" 26DP "/> <progressbar android:id=" @+id/my_customprogressbar4 "         style= "@style/mycustom_progressbar_hor" android:layout_width= "200DP" android:layout_height= "Wrap_content" android:layout_below= "@+id/my_customprogressbar3" android:layout_centerhorizontal= "true" Android:lay        out_margintop= "22DP" android:max= "android:progress=" "android:secondaryprogress="/>        <progressbar android:id= "@+id/my_customprogressbar5" style= "@style/mycustom_progressbar_hor2" Android:layout_width= "200DP" android:layout_height= "wrap_content" android:layout_alignleft= "@+id/my_custompr OGRESSBAR4 "Android:layout_below= "@+id/my_customprogressbar4" android:layout_margintop= "26DP" android:max= "Androi" d:progress= "android:secondaryprogress="/> </RelativeLayout>

The first circular ProgressBar only rotates a picture:

Code for Style:

<style name= "Mycustom_progressbar1" >        <item name= "android:indeterminatedrawable" > @drawable/ progressbar_ver_image</item>        <item name= "android:minheight" >30dp</item>        <item name= "Android:minwidth" >30dp</item>        <item name= "android:maxheight" >60dp</item>        <item Name= "Android:maxwidth" >60dp</item>    </style>

Progressbar_ver_image's Code:

<?xml version= "1.0" encoding= "Utf-8"?><!--define a rotated animation, the picture is our custom--><rotate xmlns:android= "/http Schemas.android.com/apk/res/android "    android:drawable=" @drawable/resizeapi "    android:fromdegrees=" 0 "    android:pivotx= "50%"    android:pivoty= "50%"    android:todegrees= "></rotate>"


The second type of circular ProgressBar uses an animation:

Style

<style name= "Mycustom_progressbar2" >        <item name= "android:indeterminatedrawable" > @drawable/ progressbar_ver_animation</item>        <item name= "android:minheight" >60dp</item>        <item Name= "Android:minwidth" >60dp</item>        <item name= "Android:maxheight" >100dp</item>        <item name= "Android:maxwidth" >100dp</item>    </style>

Progressbar_ver_animation's Code:

<?xml version= "1.0" encoding= "Utf-8"? ><animation-list xmlns:android= "http://schemas.android.com/apk/res/ Android ">    <item        android:drawable=" @drawable/ok1 "        android:duration="/> <item        android:drawable= "@drawable/ok2"        android:duration= "/>    <item        android:drawable=" @ Drawable/ok3 "        android:duration=" "/>    <item        android:drawable=" @drawable/ok4 "        android: duration= "/></animation-list>"


The third round ProgressBar uses shape to build drawable:

<style name= "Mycustom_progressbar3" >        <item name= "android:indeterminatedrawable" > @drawable/ progressbar_ver_shape</item>        <item name= "android:minheight" >60dp</item>        <item name= "Android:minwidth" >60dp</item>        <item name= "Android:maxheight" >100dp</item>        < Item Name= "Android:maxwidth" >100dp</item>    </style>

Progressbar_ver_shape's Code:

<?xml version= "1.0" encoding= "Utf-8"?><!--define a rotated animation, the picture is our custom shape--><rotate xmlns:android= "http:/ /schemas.android.com/apk/res/android "    android:fromdegrees=" 0 "    android:pivotx=" 50% "    android:pivoty= "50%"    android:todegrees= "<shape" >        android:innerradiusratio= "3"        android:shape= "Ring"        android:thicknessratio= "8"        android:uselevel= "false" >        <gradient            android:centercolor= "# FFFFFF "            android:centery=" 0.50 "            android:endcolor=" #1E90FF "            android:startcolor=" #000000 "            Android:type= "Sweep"            android:uselevel= "false"/>    </shape></rotate>

Fourth: Horizontal ProgressBar copy and paste the system's style, then modify:

<?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:ra dius= "5dip"/> <gradient android:startcolor= "#ffff0000" Android:cen                    Tercolor= "#ffff0000" android:centery= "0.75" android:endcolor= "#ffff0000" Android:angle= "/> </shape> </item> <item android:id=" @android: ID /secondaryprogress "> <clip> <shape> <corners android:radius=" 5dip "/&gt                ;                        <gradient android:startcolor= "#800000ff" android:centercolor= "#800000ff" android:centery= "0.75" android:endcolor= "#800000ff" a  Ndroid:angle= "270"              /> </shape> </clip> </item> <item android:id= "@android: ID /progress "> <clip > <shape> <corners android:radius= "5dip"/> <gradient android:startcolor= "#ff00ff00" Android Oid:centercolor= "#ff00ff00" android:centery= "0.75" android:endcolor= "#ff00ff xx "android:angle="/> </shape> </clip> < /item> </layer-list>

This style can be met directly in ProgressBar, and of course we can also ProgressBar background progress secondprogress are defined as a drawable, and then use:

Background

<shape xmlns:android= "Http://schemas.android.com/apk/res/android" >    <corners android:radius= "5dip"/ >    <gradient        android:angle= "android:centercolor="        #ffff0000 "        android:centery=" 0.75 "        android:endcolor= "#ffff0000"        android:startcolor= "#ffff0000"/></shape>

Progress

<shape xmlns:android= "Http://schemas.android.com/apk/res/android" >    <corners android:radius= "5dip"/ >    <gradient        android:angle= "android:centercolor="        #ff00ff00 "        android:centery=" 0.75 "        android:endcolor= "#ff00ff00"        android:startcolor= "#ff00ff00"/></shape>

Secondprogress:

<shape xmlns:android= "Http://schemas.android.com/apk/res/android" >    <corners android:radius= "5dip"/ >    <gradient        android:angle= "android:centercolor="        #800000ff "        android:centery=" 0.75 "        android:endcolor= "#800000ff"        android:startcolor= "#800000ff"/></shape>

This time the code in the style will be a little clearer:

<?xml version= "1.0" encoding= "Utf-8"? ><layer-list xmlns:android= "http://schemas.android.com/apk/res/ Android ">    <item        android:id=" @android: Id/background "        android:drawable=" @drawable/progressbar_ HOR_BG ">    </item>    <item android:id=" @android: id/secondaryprogress ">        <clip android: drawable= "@drawable/progressbar_hor_second_progress" >        </clip>    </item>    <item Android:id= "@android: id/progress" >        <clip android:drawable= "@drawable/progressbar_hor_progress" >        </clip>    </item>    <!--Progress This place was written by the original author of a dot 9--      <!--<item Android: Id= "@android: id/progress" >          <clip>              <nine-patch android:src= "@drawable/progress_patch_galy" />          </clip>      </item>   --></layer-list>


Hey.. Finally, to be honest: God General man's original blogger blog Connection http://blog.csdn.net/mad1989/article/details/38042875


By the way, the code is still posted. Always feel more comfortable reading the code directly in the IDE: http://download.csdn.net/detail/u010399316/9000197


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Custom level and circle ProgressBar only define some style to

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.