• 进度条控件的使用


     1 package com.example.helloworld;
     2 
     3 import android.app.Activity;
     4 import android.os.Bundle;
     5 import android.view.View;
     6 import android.view.View.OnClickListener;
     7 import android.widget.Button;
     8 import android.widget.ProgressBar;
     9 
    10 /**
    11  * 常用控件三 ProgressBar ListView
    12  * 
    13  * @author David
    14  * 
    15  */
    16 public class TenLessonDemo1 extends Activity {
    17 
    18     private ProgressBar firstBar = null;
    19     private ProgressBar secondBar = null;
    20     private Button myButton = null;
    21     private int i = 0;
    22 
    23     @Override
    24     protected void onCreate(Bundle savedInstanceState) {
    25         // TODO Auto-generated method stub
    26         super.onCreate(savedInstanceState);
    27         this.setContentView(R.layout.tenone);
    28         firstBar = (ProgressBar) findViewById(R.id.firstBar);
    29         secondBar = (ProgressBar) findViewById(R.id.secondBar);
    30         myButton = (Button) findViewById(R.id.myButton);
    31         myButton.setOnClickListener(new ButtonListener());
    32         System.out.println(firstBar.getMax());
    33     }
    34 
    35     class ButtonListener implements OnClickListener {
    36 
    37         public void onClick(View arg0) {
    38             // TODO Auto-generated method stub
    39             if (i == 0) {
    40                 firstBar.setVisibility(View.VISIBLE);//设置进度条处于可见状态
    41                 secondBar.setVisibility(View.VISIBLE);
    42             } else if (i < firstBar.getMax()) {
    43                 firstBar.setProgress(i);//设置进度条的当前值
    44                 firstBar.setSecondaryProgress(i + 10);//进度条的第二颜色
    45                 secondBar.setProgress(i);//这样做是没有作用的,因为默认的进度条是无法显示进行的状态的
    46             } else {
    47                 firstBar.setVisibility(View.GONE);
    48                 secondBar.setVisibility(View.GONE);//设置进度条处于不可见状态
    49 
    50             }
    51             i = i + 10;
    52         }
    53     }
    54 }
     1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2     android:layout_width="fill_parent"
     3     android:layout_height="fill_parent"
     4     android:orientation="vertical" >
     5 
     6     <TextView
     7         android:id="@+id/textView1"
     8         android:layout_width="fill_parent"
     9         android:layout_height="wrap_content"
    10         android:text="hello" />
    11 
    12     <ProgressBar
    13         android:id="@+id/firstBar"
    14         style="?android:attr/progressBarStyleHorizontal"
    15         android:layout_width="200dp"
    16         android:layout_height="wrap_content"
    17         android:max="200"
    18         android:visibility="gone" />
    19 
    20     <ProgressBar
    21         android:id="@+id/secondBar"
    22         style="?android:attr/progressBarStyle"
    23         android:layout_width="wrap_content"
    24         android:layout_height="wrap_content"
    25         android:visibility="gone" />
    26 
    27     <Button
    28         android:id="@+id/myButton"
    29         android:layout_width="wrap_content"
    30         android:layout_height="wrap_content"
    31         android:text="确定" />
    32 
    33 </LinearLayout>

    --------------------------------------------------------------------------------------------------------------------------------------------
    顺势而为
  • 相关阅读:
    置换笔记
    7.23
    Conveyor Belts
    CF #134 A~D
    Blocks && Fixing the Great wall
    Kakuro
    Deadlock Detection
    关于KeyFile的破解,含注册机源代码
    BMP位图之代码实现
    BMP位图之8位位图(三)
  • 原文地址:https://www.cnblogs.com/zhuzhenyu/p/2616112.html
Copyright © 2020-2023  润新知