生活随笔
收集整理的這篇文章主要介紹了
Android超简单的进度条源码
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
相信大家都知道,打開程序的時(shí)候,需要通過進(jìn)度條或者圖片顯示。這個(gè)時(shí)候很方便給應(yīng)用程序優(yōu)質(zhì)的效果。下面我們來看看是如何實(shí)現(xiàn)進(jìn)度條的代碼,原理非常簡(jiǎn)單。
如圖:
下面我們來看一下代碼的實(shí)現(xiàn)。
package com.smart;import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ProgressBar;public class Main extends Activity {private ProgressBar pro1;private ProgressBar pro2;private Handler handler=new Handler();private int count1=0;private int count2=0;//進(jìn)度條的從0開始private Runnable doUpdateProgressBar1=new Runnable() {@Overridepublic void run() {for ( count1 = 0; count1 < pro1.getMax(); count1++) {handler.post(new Runnable() {//增加進(jìn)度@Overridepublic void run() {pro1.setProgress(count1);}});}}};private Runnable doUpdateProgressBar2=new Runnable() {@Overridepublic void run() {for ( count2 = 0; count2 < pro2.getMax(); count2++) {handler.post(new Runnable() {@Overridepublic void run() {pro2.setProgress(count2);}});}}};@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);pro1=(ProgressBar)findViewById(R.id.progressBar1);//得到組件pro2=(ProgressBar)findViewById(R.id.progressBar2);Thread thread1=new Thread(doUpdateProgressBar1,"thread1");thread1.start();//開始Thread thread2=new Thread(doUpdateProgressBar2,"thread2");thread2.start();}
}<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><ProgressBarandroid:id="@+id/progressBar1"android:layout_width="fill_parent"android:layout_height="wrap_content"style="?android:attr/progressBarStyleHorizontal"android:max="20000"/><ProgressBarandroid:id="@+id/progressBar2"android:layout_width="fill_parent"android:layout_height="wrap_content"style="?android:attr/progressBarStyleHorizontal"android:max="20000"android:layout_marginTop="10dp"/></LinearLayout>
轉(zhuǎn)載于:https://www.cnblogs.com/llb988/archive/2011/03/17/1987004.html
總結(jié)
以上是生活随笔為你收集整理的Android超简单的进度条源码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。