android ProgressBar 的使用
1. main文件
<?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" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyleHorizontal" android:layout_width="255dp" android:layout_height="wrap_content" android:visibility="gone" /> <ProgressBar android:id="@+id/progressBar2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" /> <Button android:id="@+id/button" android:text="Ok" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
2. java 文件的写法
package com.android.voew; 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; /** * * @author liuqing * @version 1.0 * @see Android ProgreeBar 的使用 * 2011-10-12 * */ public class Viewchapter3Activity extends Activity { /** Called when the activity is first created. */ private ProgressBar firstProgree; private ProgressBar secondProgree; private Button button; private int i = 0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); this.firstProgree = (ProgressBar)this.findViewById(R.id.progressBar1); this.secondProgree = (ProgressBar)this.findViewById(R.id.progressBar2); this.button = (Button)this.findViewById(R.id.button); this.button.setOnClickListener(new ButtonListener()); } //添加OnClickListener方法 class ButtonListener implements OnClickListener { @Override public void onClick(View v) { if (i == 0) { firstProgree.setMax(150); secondProgree.setMax(150); firstProgree.setVisibility(View.VISIBLE); secondProgree.setVisibility(View.VISIBLE); button.setText("Begin"); i++; } else { firstProgree.setProgress(i * 10); //设进度条的从进度属性 firstProgree.setSecondaryProgress((i * 10) + 10); secondProgree.setProgress(i * 10); if (firstProgree.getMax() <= i * 10) { firstProgree.setVisibility(View.GONE); i = 0; button.setText("OK"); secondProgree.setVisibility(View.GONE); } i++; } } } }