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 {@Overridepublic 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++;}}        }}

更多相关文章

  1. Android Layout布局文件里的android:layout_height等属性为什么
  2. Android 自动编译、打包生成apk文件 3 - 使用SDK Ant方式
  3. Android 打包之三配置文件
  4. Android库so文件及skia函数的调用

随机推荐

  1. Android启动过程深入解析
  2. Android(安卓)线性布局(LinearLayout)内
  3. android客户端和servlet服务端的简单登录
  4. 如何在你的本上或者pc上运行 Android(安
  5. 详解 Android(安卓)的 Activity 组件
  6. Android(安卓)智能手机开发概述
  7. Android进阶(一)几种网络请求方式详解
  8. android核心模块及相关技术
  9. 【贪吃蛇—Java程序员写Android游戏】系
  10. Android(安卓)组件属性