Look first:
This is an open source control button view on GitHub ( click here to view ) with progress.
How to use: Download the project from GitHub and import it into Eclipse, then as a library, and then directly reference it in other projects. However, I feel that the individual detail code in the native project is not too perfect, and I added some fields and methods to its Masterlayout.java class:
Added value, by philpublic static final int START = 1, PAUSE = 2, complete = 3;//increment method, by philpublic int getState () {return FL G_frmwrk_mode;}
The newly added values and methods are primarily used to determine the state of the current view.
Now I'm going to give you an example of my improved usage:
Package Zhangphil.progressbutton;import Com.thbs.progressbutton.masterlayout;import Android.support.v7.app.actionbaractivity;import Android.view.view;import Android.widget.textview;import Android.widget.toast;import Android.os.asynctask;import Android.os.bundle;import Android.os.SystemClock;public Class Mainactivity extends Actionbaractivity {private masterlayout masterlayout;private longtimeoperationtask mTask;// Show progress text private TextView TV, @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.activity_main); masterlayout = (masterlayout) findViewById ( r.id.progress) Masterlayout.setonclicklistener (new View.onclicklistener () {@Overridepublic void OnClick (View v) {// You must have this method, which is the beginning of the animation progress. Executes immediately when the user taps the button. Masterlayout.animation ();//The judging code here is judged by the current view type. If the current view is the icon that starts, and the user clicks it, it starts. The time-consuming operations of the user, such as downloading tasks, are completed. if (masterlayout.getstate () = = Masterlayout.start) {toast.maketext (Mainactivity.this, "Start ...", Toast.length_short). Show (); mtask = new Longtimeoperationtask (); Mtask.execute (); The user clicked the Stop button. Cancels the task. if (masterlayout.getstate () = = Masterlayout.pause) {if (Mtask! = null&& Mtask.getstatus () = = AsyncTask.Status.RUNNING) Mtask.cancel (TRUE);//Reset () resets the space to the most initialized stage. Masterlayout.reset (); Toast.maketext (Mainactivity.this, "Stop! ", Toast.length_short). Show ();} The view control shown here is a checkmark icon. if (masterlayout.getstate () = = Masterlayout.complete) {toast.maketext (mainactivity.this, "Done!", Toast.length_short). Show ();}}); TV = (TextView) Findviewbyid (r.id.tv);} Private class Longtimeoperationtask extendsasynctask<string, Integer, string> {@Overrideprotected void OnPreExecute () {} @Overrideprotected string Doinbackground (Final String ... args) {//progress is identified by percentile. for (int i = 0; I <=; i++) {systemclock.sleep (+);p ublishprogress (i);} return null;} @Overrideprotected void Onprogressupdate (Integer ... progress) {//Here Setupprogress update the progress of the circular button. MasterLayout.cusview.setupprogress (Progress[0]);//An additional TextView shows the progress. Tv.settext (PRogress[0] + "%");}}}
Activity_main.xml file:
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Match_ Parent " android:layout_height=" match_parent " android:orientation=" vertical "> < Com.thbs.progressbutton.MasterLayout android:id= "@+id/progress" android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:clickable= "true"/> <textview android:id= "@ +id/tv " android:layout_width=" wrap_content " android:layout_height=" Wrap_content " android: gravity= "center" android:text= "10%"/></linearlayout>
Android Round line button with progress display