ProgressBar进度条的使用:

<?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"><TextView android:layout_width="fill_parent"android:layout_height="wrap_content" android:text="@string/hello" /><ProgressBar android:id="@+id/ProgressBar01"style="?android:attr/progressBarStyleHorizontal" android:visibility="gone"android:layout_width="fill_parent" android:layout_height="wrap_content"></ProgressBar><ProgressBar android:id="@+id/ProgressBar02"android:visibility="gone" android:max="100" android:progress="50"android:secondaryProgress="70" style="?android:attr/progressBarStyleLarge"android:layout_width="wrap_content" android:layout_height="wrap_content"></ProgressBar><Button android:id="@+id/Button" android:text="start"android:layout_width="wrap_content" android:layout_height="wrap_content"></Button></LinearLayout>


package com.Aina.Android;import android.app.Activity;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.view.View;import android.view.Window;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ProgressBar;public class Test_ProgressBar extends Activity {/** Called when the activity is first created. */private ProgressBar pBar1, pBar2;private Button btn;protected static final int STOP = 0x108;protected static final int NEXT = 0x109;private int iCount = 0;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);this.requestWindowFeature(Window.FEATURE_PROGRESS);// 设置窗口属性this.setProgressBarVisibility(true);// 显示setContentView(R.layout.main);pBar1 = (ProgressBar) this.findViewById(R.id.ProgressBar01);pBar2 = (ProgressBar) this.findViewById(R.id.ProgressBar02);btn = (Button) this.findViewById(R.id.Button);pBar1.setIndeterminate(false);pBar2.setIndeterminate(false);btn.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubpBar1.setVisibility(View.VISIBLE);pBar2.setVisibility(View.VISIBLE);// 设置为可见pBar1.setMax(100);// 设置最大值pBar1.setProgress(0);pBar2.setProgress(0);// 设置当前值new Thread(new Runnable(){@Overridepublic void run() {// TODO Auto-generated method stubfor(int i=0;i<10;i++){try{iCount = (i+1)*20;Thread.sleep(1000);if(i==4){Message msg = new Message();msg.what = STOP;Test_ProgressBar.this.mHandler.sendMessage(msg);break;}else{Message msg= new Message();msg.what = NEXT;Test_ProgressBar.this.mHandler.sendMessage(msg);}}catch(Exception ex){ex.printStackTrace();}}}}){}.start();}});}private Handler mHandler = new Handler() {public void handleMessage(Message msg) {switch(msg.what){case STOP://到了最大值pBar1.setVisibility(View.GONE);pBar2.setVisibility(View.GONE);//设置进度条不可见Thread.currentThread().interrupt();//中断当前线程.break;case NEXT:if(!Thread.currentThread().isInterrupted()){//当前线程正在运行pBar1.setProgress(iCount);pBar2.setProgress(iCount);//设置当前值Test_ProgressBar.this.setProgress(iCount*100);Test_ProgressBar.this.setSecondaryProgress(iCount*100);}break;}super.handleMessage(msg);}};}

更多相关文章

  1. ProgressBar的样式及用法
  2. wifi和GPRS下获取android的IP信息
  3. 安卓布局
  4. Android(安卓)Activity onConfigurationChanged()方法 监听状态
  5. [长姿势了]android:padding和android:margin的区别
  6. textview中有很多行,我只让它显示三行,最后显示...,我设置了androi
  7. android:layout_gravity和android:gravity属性的区别
  8. Android之Shape和state_enabled使用总结
  9. android升级adt和sdk之后无法识别SDK Location的一个解决方式

随机推荐

  1. Android(安卓)6.0之后的动态权限
  2. Android消息处理机制(二)
  3. android TextView多行文本(超过3行)使用e
  4. 【Android】ListView与Button的共存问题
  5. ListActivity中android:id="@+id/android
  6. Android(安卓)可以自定义速度的跑马灯效
  7. Android的简介
  8. Android(安卓)2.2 demos -- Window Featu
  9. Android和Linux kernel发展史
  10. Android(安卓)Camera