Android中ProgressBar用法簡單實(shí)例
本文實(shí)例講述了Android中ProgressBar用法。分享給大家供大家參考,具體如下:
在android中會經(jīng)常用到ProgressBar,下面通過舉例來說明如何使用ProgressBar。
import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ProgressBar; public class A03Activity extends Activity { private ProgressBar rectangle,circle; private Button showProgressBar; private final static int STOP=0x10000; private final static int NEXT=0x10001; private int count=0; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); rectangle=(ProgressBar)findViewById(R.id.rectangle); circle=(ProgressBar)findViewById(R.id.circle); showProgressBar=(Button)findViewById(R.id.showProgressBar); rectangle.setIndeterminate(false); circle.setIndeterminate(false); showProgressBar.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub rectangle.setVisibility(View.VISIBLE); circle.setVisibility(View.VISIBLE); rectangle.setMax(100); rectangle.setProgress(0); circle.setProgress(0); Thread t=new Thread(new Runnable(){ @Override public void run() { // TODO Auto-generated method stub for(int i=0;i<20;i++){ try { count=(i+1)*5; Thread.sleep(1000); if(count==19){ Message msg=new Message(); msg.what=STOP; handler.sendMessage(msg); break; } else{ Message msg=new Message(); msg.what=NEXT; handler.sendMessage(msg); } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }); t.start(); } }); } private Handler handler=new Handler(){ @SuppressWarnings("static-access") public void handleMessage(Message msg){ switch(msg.what){ case STOP: rectangle.setVisibility(View.GONE); circle.setVisibility(View.GONE); Thread.currentThread().interrupt(); break; case NEXT: if(!Thread.currentThread().interrupted()){ rectangle.setProgress(count); circle.setProgress(count); } break; } } }; }
res/layout/main.xml如下所示:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <ProgressBar android:id="@+id/rectangle" android:layout_width="fill_parent" android:layout_height="wrap_content" style="?android:attr/progressBarStyleHorizontal" mce_style="?android:attr/progressBarStyleHorizontal" android:visibility="gone" /> <ProgressBar android:id="@+id/circle" android:layout_width="wrap_content" android:layout_height="wrap_content" style="?android:attr/progressBarStyleLarge" mce_style="?android:attr/progressBarStyleLarge" android:visibility="gone" /> <Button android:id="@+id/showProgressBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="show ProgressBar" /> </LinearLayout>
更多關(guān)于Android控件相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
- 解析android中ProgressBar的用法
- Android ProgressBar進(jìn)度條和ProgressDialog進(jìn)度框的展示DEMO
- Android自定義ProgressDialog進(jìn)度等待框
- Android ProgressBar進(jìn)度條使用詳解
- Android三種方式實(shí)現(xiàn)ProgressBar自定義圓形進(jìn)度條
- Android ProgressDialog進(jìn)度條使用詳解
- 加載頁面遮擋耗時(shí)操作任務(wù)頁面--第三方開源之AndroidProgressLayout
- Android編程之ProgressBar圓形進(jìn)度條顏色設(shè)置方法
- Android中Progress的簡單實(shí)例
相關(guān)文章
Android編程中常用適配器及自定義適配器用法實(shí)例分析
這篇文章主要介紹了Android編程中常用適配器及自定義適配器用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android中適配器的概念、功能及自定義適配器的相關(guān)使用技巧,需要的朋友可以參考下2015-11-11Android 自定義加載動畫Dialog彈窗效果的示例代碼
這篇文章主要介紹了Android 自定義加載動畫Dialog彈窗效果,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06基于Android XML解析與保存的實(shí)現(xiàn)
本篇文章小編為大家介紹,基于Android XML解析與保存的實(shí)現(xiàn)。需要的朋友參考下2013-04-04如何利用adb卸載手機(jī)預(yù)裝軟件(系統(tǒng)軟件)
對于Android手機(jī)通常有很多不必要的預(yù)置軟件,但是又無法卸載,占用桌面有很難受,所以本次使用adb工具來實(shí)現(xiàn)從電腦命令來卸載或停用軟件,下面這篇文章主要給大家介紹了關(guān)于如何利用adb卸載手機(jī)預(yù)裝軟件(系統(tǒng)軟件)的相關(guān)資料,需要的朋友可以參考下2022-09-09利用Kotlin的協(xié)程實(shí)現(xiàn)簡單的異步加載詳解
這篇文章主要給大家介紹了關(guān)于利用Kotlin的協(xié)程實(shí)現(xiàn)簡單的異步加載的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-03-03Android12四大組件之Activity生命周期變化詳解
雖然說我們天天都在使用Activity,但是你真的對Activity的生命機(jī)制完全了解了嗎?Activity的生命周期方法只有七個,但是其實(shí)那只是默認(rèn)的情況。也就是說在其他情況下,Activity的生命周期可能不會是按照我們以前所知道的流程,本章著重講解Activity的生命周期變化2022-07-07RadioButton實(shí)現(xiàn)選擇后可取消選擇
這篇文章主要為大家詳細(xì)介紹了RadioButton實(shí)現(xiàn)選擇后可取消選擇,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-08-08android實(shí)現(xiàn)輪播圖引導(dǎo)頁
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)輪播圖引導(dǎo)頁,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-09-09Android自定義View實(shí)現(xiàn)支付寶支付成功-極速get花式Path炫酷動畫
這篇文章主要介紹了Android自定義View實(shí)現(xiàn)支付寶支付成功-極速get花式Path炫酷動畫的相關(guān)資料,非常不錯,具有參考借鑒價(jià)值,需要的朋友可以參考下2017-01-01Android onClick方法與setOnClickListener方法對比
這篇文章主要介紹了Android onClick方法與setOnClickListener方法對比的相關(guān)資料,這兩個方法都是點(diǎn)擊事件處理函數(shù)的方法,它們之間到底有什么區(qū)別呢,下面就給大家說下,需要的朋友可以參考下2016-12-12