欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

进度条ProgressBar应用 博客分类: android androidprogressBar

程序员文章站 2024-03-14 22:48:23
...

layout的配置文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world"
        tools:context=".Activity02" />
	<ProgressBar 
	    android:id="@+id/pro1"
	    android:layout_width="fill_parent"
	    android:layout_height="wrap_content"
	    android:visibility="gone"
	    style="?android:attr/progressBarStyleHorizontal"
	    />
    <ProgressBar 
        android:id="@+id/pro2"
	    android:layout_width="fill_parent"
	    android:layout_height="wrap_content"
	    android:visibility="gone"
	    style="?android:attr/progressBarStyleInverse"
        />
    
    <Button 
        android:id="@+id/button"
        android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:layout_margin="10pt"
        />
</LinearLayout>

 

代码:

package com.example.progressbar;

import android.opengl.Visibility;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;

public class Activity02 extends Activity {
	
	ProgressBar pro1;
	ProgressBar pro2;
	Button button;
	private int i = 0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_activity02);
        
        pro1 = (ProgressBar) findViewById(R.id.pro1);
        pro2 = (ProgressBar) findViewById(R.id.pro2);
        button = (Button) findViewById(R.id.button);
        
        button.setText("确定");
        
        button.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				if(i==0){
					pro1.setVisibility(View.VISIBLE);
					pro2.setVisibility(View.VISIBLE);
				}
				else if (i<100){
					pro1.setProgress(i);
					pro1.setSecondaryProgress(i+10);
					pro2.setProgress(i);
					pro2.setSecondaryProgress(i+10);
				}else{
					pro1.setVisibility(View.GONE);
					pro2.setVisibility(View.GONE);
				}
				i=i+10;
			}
		});
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_activity02, menu);
        return true;
    }
}

 

 

相关标签: android progressBar