This article briefly describes the Android custom ProgressBar.
Many do not say, first
Layout file
Activity_main.xml
<linearlayout 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 "Android:paddi ngbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_horizontal_margin" Android: paddingright= "@dimen/activity_horizontal_margin" android:paddingtop= "@dimen/activity_vertical_margin" tools: Context= ". Mainactivity "android:orientation=" vertical "> <textview android:layout_width=" wrap_content "and roid:layout_height= "Wrap_content" android:text= "@string/hello_world" android:padding= "5DP"/> <Prog Ressbar android:id= "@+id/progress1" android:layout_width= "wrap_content" android:layout_height= "Wrap_ Content "android:padding=" 5DP "/> <progressbar android:id=" @+id/progress2 "style="? a Ndroid:attr/progressbarstylehorizontal "Android: "Match_parent" android:layout_height= "wrap_content" android:max= "layout_width=" android:progress= "Android:secondaryprogress=" android:padding= "5DP"/> <progressbar android:id= "@+id/p Rogress3 "style="? Android:attr/progressbarstylehorizontal "Android:layout_width=" Match_parent "Androi d:layout_height= "Wrap_content" android:max= "android:progress=" android:secondaryprogress= "80" android:progressdrawable= "@drawable/progress_horizontal" android:padding= "5DP"/> <progressbar Android:id= "@+id/progress4" style= "Android:attr/progressbarstylehorizontal" android:layout_width= "fill_p Arent "android:layout_height=" 25DP "android:max=" android:progress= "Android:paddinglef" t= "1DP" android:paddingright= "1DP" android:progressdrawable= "@drawable/progressbar_layer_list" Androi d:padding= "5DP"/><progressbar android:id= "@+id/progress5" android:layout_width= "30dip" android:layout_height= "30 Dip "android:indeterminatedrawable=" @drawable/progress_selector "android:visibility=" visible "/> <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:tex T= "Progress Value" android:padding= "5DP"/> <linearlayout android:layout_width= "Match_parent" android:layout_height= "wrap_content" android:orientation= "Horizontal" > <button android: Id= "@+id/btn1" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" a ndroid:text= "Value-"/> <button android:id= "@+id/btn2" android:layout_width= "Wrap_cont Ent "android:layout_height=" wrap_content "android:text=" value + "/> </LinearLayout> &l T TextView AndroiD:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:text= "second progress value" android:padding= "5DP"/> <linearlayout android:layout_width= "Match_parent" Android:layout_heigh t= "wrap_content" android:orientation= "horizontal" > <button android:id= "@+id/btn3" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "Value-"/& Gt <button android:id= "@+id/btn4" android:layout_width= "Wrap_content" Android:layout_hei ght= "Wrap_content" android:text= "value +"/> </LinearLayout></LinearLayout>
Files associated with layout files
Progress_horizontal.xml
<?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=" @color/red "> </item> <item android:id= "@android: id/secondaryprogress" > <scale android:drawable= "@ Color/green " android:scalewidth=" 100% "/> </item> <item android:id=" @android: id/progress "> <scale android:drawable=" @color/blue " android:scalewidth=" 100% "/> </item ></layer-list>
Progressbar_layer_list.xml
<?xml version= "1.0" encoding= "Utf-8"? ><layer-list xmlns:android= "http://schemas.android.com/apk/res/ Android "><itemandroid:id=" @android: Id/background "android:drawable=" @drawable/pic2 "></item>< Itemandroid:id= "@android: Id/progress" android:drawable= "@drawable/pic1" ></item></layer-list>
Progress_selector.xml
<?xml version= "1.0" encoding= "UTF-8"? ><rotate xmlns:android= "Http://schemas.android.com/apk/res/android" android:pivotx= "50%" android:pivoty= "50%" android:fromdegrees= "0" android:todegrees= "the" ><shapeandroid: Shape= "Ring" android:innerradiusratio= "3" android:thicknessratio= "8" android:uselevel= "false" ><gradient Android:type= "Sweep" android:uselevel= "false" android:startcolor= "#871318" android:centercolor= "#D5202A" Android: centery= "0.50" android:endcolor= "#FFEEEE"/></shape></rotate>
Main program
Package Com.sl.progressbardemo;import Android.os.bundle;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.window;import Android.widget.button;import Android.widget.progressbar;import Android.app.activity;public class Mainactivity extends Activity{private ProgressBar mprogressbar2;private ProgressBar mprogressbar3;private ProgressBar mprogressbar4;private Button mButton1 ;p rivate button mbutton2;private button mbutton3;private button mButton4; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Requestwindowfeature (window.feature_progress); Setcontentview (R.layout.activity_main); setprogressbarvisibility (true); mProgressBar2 = (ProgressBar) Findviewbyid ( R.ID.PROGRESS2); mProgressBar3 = (ProgressBar) Findviewbyid (R.ID.PROGRESS3); MPROGRESSBAR4 = (ProgressBar) Findviewbyid (R.ID.PROGRESS4); mButton1 = (Button) Findviewbyid (R.ID.BTN1); mButton2 = (Button) Findviewbyid (R.ID.BTN2) ; MButton3 = (Button) Findviewbyid (R.ID.BTN3); MbuttOn4 = (Button) Findviewbyid (R.ID.BTN4); Mbutton1.setonclicklistener (listener); Mbutton2.setonclicklistener (listener ); Mbutton3.setonclicklistener (listener); Mbutton4.setonclicklistener (listener);} Button.onclicklistener listener = new Onclicklistener () {@Overridepublic void OnClick (View v) {button button = (button) v; Switch (Button.getid ()) {case R.id.btn1:mprogressbar2.incrementprogressby ( -5); Mprogressbar3.incrementprogressby (- 5); Mprogressbar4.incrementprogressby ( -5); break;case R.id.btn2:mprogressbar2.incrementprogressby (5); Mprogressbar3.incrementprogressby (5); Mprogressbar4.incrementprogressby (5); Break;case R.id.btn3: Mprogressbar2.incrementsecondaryprogressby ( -5); Mprogressbar3.incrementsecondaryprogressby ( -5); break;case R.id.btn4:mprogressbar2.incrementsecondaryprogressby (5); Mprogressbar3.incrementsecondaryprogressby (5); break; Default:break;}}};}
SOURCE download
Android Custom ProgressBar