您的位置:首页 > 其它

安卓第十天——Progress组件的简单实现

2011-12-22 22:48 211 查看
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;



}









}





}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: