一、Progress:表示进度条,本程序在标题栏和Activaty中分别加入进度条。

二、XML重要属性

    android:progressBarStyle:默认进度条样式

    android:progressBarStyleHorizontal:水平样式

 

三、重要方法

    getMax():返回这个进度条的范围的上限

    getProgress():返回进度

    getSecondaryProgress():返回次要进度

    incrementProgressBy(int diff):指定增加的进度

    isIndeterminate():指示进度条是否在不确定模式下

    setIndeterminate(boolean indeterminate):设置不确定模式下

    setVisibility(int v):设置该进度条是否可视

四、重要事件

    onSizeChanged(int w, int h, int oldw, int oldh):当进度值改变时引发此事件

效果图:

 

 

 

layout中的xml文件:

 
  
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  2.     android:layout_width="match_parent" 
  3.     android:layout_height="match_parent" 
  4.     android:orientation="vertical" 
  5.     android:background="#00ff00"> 
  6.       
  7.     <ProgressBar    
  8.         android:id="@+id/myProgressBar" 
  9.         android:layout_width="wrap_content" 
  10.         android:layout_height="wrap_content" 
  11.         style="?android:attr/progressBarStyleSmall"  //设置进度条的模式为圆圈旋转模式
  12.         /> 
  13.     <ProgressBar   
  14.         android:id="@+id/myProgressBar2" 
  15.         android:layout_width="fill_parent" 
  16.         android:layout_height="wrap_content" 
  17.         style="?android:attr/progressBarStyleHorizontal" //设置进度条的模式为水平模式
  18.         android:max="100"  //设置进度条的最大值
  19.         android:progress="20" //设置进度条的当前值
  20.         android:secondaryProgress="50"//设置进度条的次进度值
  21. />
  22.       
  23. </LinearLayout> 

Activaty.java文件

 

 
  
  1. package com.cheng.progressbarproject;  
  2.  
  3. import android.os.Bundle;  
  4. import android.app.Activity;  
  5. import android.view.Menu;  
  6. import android.view.Window;  
  7.  
  8. public class ProgressBarActivity extends Activity {  
  9.  
  10.     @Override 
  11.     protected void onCreate(Bundle savedInstanceState) {  
  12.         super.onCreate(savedInstanceState);  
  13.           
  14.         //在窗口标题栏上加进度条,这条语句必须写在super.setContentView(R.layout.main);之前  
  15.         requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);  
  16.         super.setContentView(R.layout.main);  
  17.         //设置标题栏上的进度条是可见的  
  18.         setProgressBarIndeterminateVisibility(true);  
  19.           
  20.     }  
  21.  
  22.     @Override 
  23.     public boolean onCreateOptionsMenu(Menu menu) {  
  24.         // Inflate the menu; this adds items to the action bar if it is present.  
  25.         getMenuInflater().inflate(R.menu.main, menu);  
  26.         return true;  
  27.     }  
  28.  
  29. }