Android圓線按鈕帶進度顯示

來源:互聯網
上載者:User

標籤:android

先看:




這是一個在github上的開原始檔控制按鈕View(點擊此處查看),同時帶有進度。

使用方法:把該項目從github上下載下來匯入到eclipse,然後作為庫,接下來在其他項目中直接引用即可。然而,我感覺原生項目中的個別細節代碼不是太完善,我在它的MasterLayout.java類增加了一些欄位和方法:

// 增加的值,by Philpublic static final int START = 1, PAUSE = 2, COMPLETE = 3;// 增加的方法,by Philpublic int getState() {return flg_frmwrk_mode;}

新增加的值和方法主要用於判斷當前View的狀態。

現在給出一個經過我改進後的使用執行個體:

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;// 顯示進度文字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) {// 必須有該方法,該方法是動畫進度的開始。// 當使用者點擊該按鈕後立即執行。masterLayout.animation();// 此處的判斷代碼是根據當前的View類型判斷的。// 如果當前View是開始的那個icon,並且使用者點擊了,那麼就開始。// 在次完成使用者的耗時操作,比如下載任務等。if (masterLayout.getState() == MasterLayout.START) {Toast.makeText(MainActivity.this, "開始...",Toast.LENGTH_SHORT).show();mTask = new LongTimeOperationTask();mTask.execute();}// 使用者點擊了 停止 按鈕。取消任務。if (masterLayout.getState() == MasterLayout.PAUSE) {if (mTask != null&& mTask.getStatus() == AsyncTask.Status.RUNNING)mTask.cancel(true);// reset()是將該空間複位到最初始化的階段。masterLayout.reset();Toast.makeText(MainActivity.this, "停止!", Toast.LENGTH_SHORT).show();}// 此處的View控制項顯示是一個 對號 icon。if (masterLayout.getState() == MasterLayout.COMPLETE) {Toast.makeText(MainActivity.this, "完成!", 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) {// 進度以百分制標識。for (int i = 0; i <= 100; i++) {SystemClock.sleep(100);publishProgress(i);}return null;}@Overrideprotected void onProgressUpdate(Integer... progress) {// 此處的 setupprogress 更新圓形按鈕的進度。masterLayout.cusview.setupprogress(progress[0]);// 額外的一個TextView顯示進度。tv.setText(progress[0] + " %");}}}

activity_main.xml檔案:

<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圓線按鈕帶進度顯示

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.