Android进度条实例测试

主文件ProgressBar.java:

package com.progress;

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

public class progress extends Activity {
    /** Called when the activity is first created. */
    private ProgressBar firstBar=null;
    private ProgressBar secondBar=null;
    private Button mybutton=null;
    private int i=0;
	
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        firstBar=(ProgressBar)findViewById(R.id.firstBar);
        secondBar=(ProgressBar)findViewById(R.id.secondBar);
        mybutton=(Button)findViewById(R.id.MyButton);
        mybutton.setText("开始");
        mybutton.setOnClickListener(new ButtonListener());
        
    }
	
	
	class ButtonListener implements OnClickListener{

		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
		  	if(0==i){
		  		firstBar.setVisibility(View.VISIBLE);
		  		secondBar.setVisibility(View.VISIBLE);
		  	}else if(i<100){
		  		firstBar.setProgress(i);
		  		firstBar.setSecondaryProgress(i+10);
		  		secondBar.setProgress(i);
		  	}else{
		  		
		  		firstBar.setVisibility(View.GONE);
		  		secondBar.setVisibility(View.GONE);
		  		
		  	}
			i=i+10;
		}

	
		
		
	}
}
 

主要配置文件:main.xml

<?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/firstBar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:visibility="gone"
    
    />
<ProgressBar
    android:id="@+id/secondBar"
    style="?android:attr/progressBarStyle"   
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="gone"
    />
<Button
     android:id="@+id/MyButton"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     
     />
</LinearLayout>
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值