安卓第十天——Progress組件的簡單實現

 

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" >

  <ProgressBar
     
       android:layout_width="wrap_content"
    android:layout_height="wrap_content"
      android:max="100"
      android:visibility="invisible"
      android:id="@+id/progress1"
      />
  <ProgressBar
     
       android:layout_width="200dp"
    android:layout_height="wrap_content"
    style="@android:style/Widget.ProgressBar.Horizontal"
      android:max="100"
      android:id="@+id/progress2"
      android:visibility="invisible"
      />
 
<Button
  android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="點擊"
    android:id="@+id/button"
    />
</LinearLayout>

 

ProgressBarActivity.java

package cn.class3g.progressbar;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;

public class ProgressBarActivity extends Activity {
  
 private ProgressBar progress1 =null;
 
 private ProgressBar progress2=null;
 
 private Button button =null;
 
 private int i=0;
 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
       
        progress1 =(ProgressBar) this.findViewById(R.id.progress1);
       
        progress2 = (ProgressBar) this.findViewById(R.id.progress2);
       
        button= (Button) this.findViewById(R.id.button);
       
        button.setOnClickListener(new progress());
       
       
       
     
       
    }
   
    class progress implements OnClickListener{

     
  public void onClick(View v) {
   
   if(i==0){
    
    progress1.setVisibility(View.VISIBLE);
    progress2.setVisibility(View.VISIBLE);
    
    
   }else if(i<progress2.getMax()){
    
    progress2.setProgress(i);
    
    progress2.setSecondaryProgress(i+10);
    
    
    
   }
   
   i=i+10;
   
  }
     
     
     
     
    }
   
   
}

 

發佈了68 篇原創文章 · 獲贊 2 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章