Android實(shí)現(xiàn)圓線(xiàn)按鈕進(jìn)度效果
本文實(shí)例為大家分享了Android實(shí)現(xiàn)圓線(xiàn)按鈕進(jìn)度效果的具體代碼,供大家參考,具體內(nèi)容如下
先看效果圖:
這是一個(gè)在github上的開(kāi)源控件按鈕View(點(diǎn)擊此處查看),同時(shí)帶有進(jìn)度。
使用方法:把該項(xiàng)目從github上下載下來(lái)導(dǎo)入到eclipse,然后作為庫(kù),接下來(lái)在其他項(xiàng)目中直接引用即可。然而,我感覺(jué)原生項(xiàng)目中的個(gè)別細(xì)節(jié)代碼不是太完善,我在它的MasterLayout.java類(lèi)增加了一些字段和方法:
// 增加的值,by Phil public static final int START = 1, PAUSE = 2, COMPLETE = 3; // 增加的方法,by Phil public int getState() { return flg_frmwrk_mode; }
新增加的值和方法主要用于判斷當(dāng)前View的狀態(tài)。
現(xiàn)在給出一個(gè)經(jīng)過(guò)我改進(jìn)后的使用實(shí)例:
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; // 顯示進(jìn)度文字 private TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); masterLayout = (MasterLayout) findViewById(R.id.progress); masterLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 必須有該方法,該方法是動(dòng)畫(huà)進(jìn)度的開(kāi)始。 // 當(dāng)用戶(hù)點(diǎn)擊該按鈕后立即執(zhí)行。 masterLayout.animation(); // 此處的判斷代碼是根據(jù)當(dāng)前的View類(lèi)型判斷的。 // 如果當(dāng)前View是開(kāi)始的那個(gè)icon,并且用戶(hù)點(diǎn)擊了,那么就開(kāi)始。 // 在次完成用戶(hù)的耗時(shí)操作,比如下載任務(wù)等。 if (masterLayout.getState() == MasterLayout.START) { Toast.makeText(MainActivity.this, '開(kāi)始...', Toast.LENGTH_SHORT).show(); mTask = new LongTimeOperationTask(); mTask.execute(); } // 用戶(hù)點(diǎn)擊了 停止 按鈕。取消任務(wù)。 if (masterLayout.getState() == MasterLayout.PAUSE) { if (mTask != null && mTask.getStatus() == AsyncTask.Status.RUNNING) mTask.cancel(true); // reset()是將該空間復(fù)位到最初始化的階段。 masterLayout.reset(); Toast.makeText(MainActivity.this, '停止!', Toast.LENGTH_SHORT) .show(); } // 此處的View控件顯示是一個(gè) 對(duì)號(hào) icon。 if (masterLayout.getState() == MasterLayout.COMPLETE) { Toast.makeText(MainActivity.this, '完成!', Toast.LENGTH_SHORT) .show(); } } }); tv = (TextView) findViewById(R.id.tv); } private class LongTimeOperationTask extends AsyncTask<String, Integer, String> { @Override protected void onPreExecute() { } @Override protected String doInBackground(final String... args) { // 進(jìn)度以百分制標(biāo)識(shí)。 for (int i = 0; i <= 100; i++) { SystemClock.sleep(100); publishProgress(i); } return null; } @Override protected void onProgressUpdate(Integer... progress) { // 此處的 setupprogress 更新圓形按鈕的進(jìn)度。 masterLayout.cusview.setupprogress(progress[0]); // 額外的一個(gè)TextView顯示進(jìn)度。 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: android:layout_width='wrap_content' android:layout_height='wrap_content' android:clickable='true' /> <TextView android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:gravity='center' android:text='10%' /> </LinearLayout>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. js實(shí)現(xiàn)跳一跳小游戲2. JVM之class文件結(jié)構(gòu)3. js實(shí)現(xiàn)貪吃蛇小游戲(加墻)4. XMLDOM對(duì)象方法:對(duì)象屬性5. python對(duì)批量WAV音頻進(jìn)行等長(zhǎng)分割的方法實(shí)現(xiàn)6. Html5播放器實(shí)現(xiàn)倍速播放的方法示例7. asp.net core 認(rèn)證和授權(quán)實(shí)例詳解8. CSS linear-gradient屬性案例詳解9. Ajax報(bào)錯(cuò)400的參考解決辦法10. Python中Anaconda3 安裝gdal庫(kù)的方法
