android 進(jìn)度條組件ProgressBar
首先是main.xml文件
代碼如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ProgressBar android:id="@+id/myprobarA" style="?android:attr/progressBarStyle" android:visibility="gone" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <ProgressBar android:id="@+id/myprobarB" style="?android:attr/progressBarStyleHorizontal" android:visibility="gone" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <ProgressBar android:id="@+id/myprobarC" style="?android:attr/progressBarStyleHorizontal" android:visibility="gone" android:max="120" android:progress="0" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <ProgressBar android:id="@+id/myprobarD" android:visibility="gone" android:max="120" android:progress="50" android:secondaryProgress="70" style="?android:attr/progressBarStyleLarge" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <ProgressBar android:id="@+id/myprobarE" android:visibility="gone" android:max="120" android:progress="50" android:secondaryProgress="70" style="?android:attr/progressBarStyleSmall" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <Button android:id="@+id/mybut" android:text="顯示進(jìn)度條" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>
然后編寫(xiě)Activity.java類
代碼如下:
package com.example.myfirstproject; import java.sql.Date; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import java.util.Timer; import java.util.TimerTask; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.app.Activity; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.*; public class MainActivity extends Activity { private ProgressBar myprobarA,myprobarB,myprobarC,myprobarD,myprobarE; private Button mybut; protected static final int STOP = 1; protected static final int CONTINUE = 2; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.myprobarA = (ProgressBar)this.findViewById(R.id.myprobarA); this.myprobarB = (ProgressBar)this.findViewById(R.id.myprobarB); this.myprobarC = (ProgressBar)this.findViewById(R.id.myprobarC); this.myprobarD = (ProgressBar)this.findViewById(R.id.myprobarD); this.myprobarE = (ProgressBar)this.findViewById(R.id.myprobarE); this.mybut = (Button)this.findViewById(R.id.mybut); this.myprobarA.setIndeterminate(false); this.myprobarB.setIndeterminate(false); this.myprobarC.setIndeterminate(true); this.myprobarD.setIndeterminate(false); this.myprobarE.setIndeterminate(false); this.mybut.setOnClickListener(new OnClickListenerlmpl()); } private class OnClickListenerlmpl implements OnClickListener{ public void onClick(View view){ MainActivity.this.myprobarB.setSecondaryProgress(0); MainActivity.this.myprobarA.setVisibility(View.VISIBLE); MainActivity.this.myprobarB.setVisibility(View.VISIBLE); MainActivity.this.myprobarC.setVisibility(View.VISIBLE); MainActivity.this.myprobarD.setVisibility(View.VISIBLE); MainActivity.this.myprobarE.setVisibility(View.VISIBLE); MainActivity.this.myprobarA.setMax(120); MainActivity.this.myprobarB.setMax(120); MainActivity.this.myprobarA.setProgress(0); MainActivity.this.myprobarB.setProgress(0); new Thread(new Runnable(){ public void run(){ int count = 0; for(int i = 0;i < 10;i++){ try{ count = (i+1)*20; Thread.sleep(500); if(i==6){ Message m = new Message(); m.what = MainActivity.STOP; MainActivity.this.myMessageHandler.sendMessage(m); break; }else{ Message m = new Message(); m.arg1 = count; m.what = MainActivity.CONTINUE; MainActivity.this.myMessageHandler.sendMessage(m); } }catch(Exception ex){ ex.printStackTrace(); } } } }).start(); } } private Handler myMessageHandler = new Handler(){ public void handleMessage(Message msg){ switch(msg.what){ case MainActivity.STOP: myprobarA.setVisibility(View.GONE); myprobarB.setVisibility(View.GONE); myprobarC.setVisibility(View.GONE); myprobarD.setVisibility(View.GONE); myprobarE.setVisibility(View.GONE); Thread.currentThread().interrupt(); break; case MainActivity.CONTINUE: if(!Thread.currentThread().isInterrupted()){ myprobarA.setProgress(msg.arg1); myprobarB.setProgress(msg.arg1); myprobarC.setProgress(msg.arg1); myprobarD.setProgress(msg.arg1); myprobarE.setProgress(msg.arg1); } break; } } }; }
運(yùn)行效果:
以上就是對(duì) Android 進(jìn)度條的知識(shí)整理,后續(xù)繼續(xù)補(bǔ)充相關(guān)知識(shí),謝謝大家對(duì)本站的支持!
- android ListView和ProgressBar(進(jìn)度條控件)的使用方法
- Android三種方式實(shí)現(xiàn)ProgressBar自定義圓形進(jìn)度條
- Android ProgressBar進(jìn)度條和ProgressDialog進(jìn)度框的展示DEMO
- Android ProgressBar進(jìn)度條使用詳解
- Android編程之ProgressBar圓形進(jìn)度條顏色設(shè)置方法
- Android編程實(shí)現(xiàn)自定義ProgressBar樣式示例(背景色及一級(jí)、二級(jí)進(jìn)度條顏色)
- Android ProgressBar直線進(jìn)度條的實(shí)例代碼
- Android編程實(shí)現(xiàn)類似于圓形ProgressBar的進(jìn)度條效果
- Android開(kāi)發(fā)之ProgressBar字體隨著進(jìn)度條的加載而滾動(dòng)
- Android UI控件之ProgressBar進(jìn)度條
相關(guān)文章
Android基于方法池與回調(diào)實(shí)現(xiàn)登錄攔截的場(chǎng)景
這篇文章主要為大家介紹了Android基于方法池與回調(diào)實(shí)現(xiàn)登錄攔截的場(chǎng)景詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08Android自定義網(wǎng)絡(luò)連接工具類HttpUtil
這篇文章主要介紹了Android自定義網(wǎng)絡(luò)連接工具類HttpUtil,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11Android 動(dòng)態(tài)添加view或item并獲取數(shù)據(jù)的實(shí)例
下面小編就為大家?guī)?lái)一篇Android 動(dòng)態(tài)添加view或item并獲取數(shù)據(jù)的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-10-10Android實(shí)現(xiàn)加載時(shí)提示“正在加載,請(qǐng)稍后”的方法
在現(xiàn)在的很多應(yīng)用中,當(dāng)在加載的時(shí)候,如果頁(yè)面動(dòng)態(tài)數(shù)據(jù)較多,會(huì)有很長(zhǎng)一段時(shí)間的空白頁(yè)面,如果加上這個(gè)頁(yè)面正在加載的提示,使得應(yīng)用更加人性化。這篇文章就給大家分享了在 Android實(shí)現(xiàn)加載時(shí)提示“正在加載,請(qǐng)稍后”的方法,有需要的朋友們可以參考借鑒。2016-10-10Webview實(shí)現(xiàn)android簡(jiǎn)單的瀏覽器實(shí)例代碼
這篇文章主要介紹了Webview實(shí)現(xiàn)android簡(jiǎn)單的瀏覽器實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2016-02-02android LinearLayout 布局實(shí)例代碼
android LinearLayout 布局實(shí)例代碼,需要的朋友可以參考一下2013-04-04Andriod?Studio實(shí)現(xiàn)撥打電話和發(fā)送短信的示例代碼
這篇文章主要介紹了Andriod?Studio實(shí)現(xiàn)撥打電話和發(fā)送短信功能,Android?Studio中創(chuàng)建項(xiàng)目,然后在該項(xiàng)目中創(chuàng)建一個(gè)Module名稱為“IntentDial”,文章結(jié)合實(shí)例步驟給大家介紹的非常詳細(xì),需要的朋友參考下吧2022-03-03Android 異步獲取網(wǎng)絡(luò)圖片并處理導(dǎo)致內(nèi)存溢出問(wèn)題解決方法
Android異步獲取網(wǎng)絡(luò)圖片并處理圖片Out Of Memory內(nèi)存溢出如何解決呢?本文介紹了操作步驟,感興趣的朋友可以了解下或許對(duì)你有所幫助2013-02-02Android網(wǎng)格布局GridView學(xué)習(xí)使用
這篇文章主要為大家詳細(xì)介紹了Android網(wǎng)格布局GirdView的學(xué)習(xí)使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12