zoukankan      html  css  js  c++  java
  • ANDROID_MARS学习笔记_S01原始版_005_ProgressBar

    一、代码

    1.xml
    (1)main.xml

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     android:orientation="vertical"
     4     android:layout_width="fill_parent"
     5     android:layout_height="fill_parent"
     6     >
     7 <TextView  
     8     android:layout_width="fill_parent" 
     9     android:layout_height="wrap_content" 
    10     android:text="@string/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:visibility="gone"
    18     />
    19 <ProgressBar
    20     android:id="@+id/secondBar"
    21     style="?android:attr/progressBarStyle"
    22     android:layout_width="wrap_content"
    23     android:layout_height="wrap_content"
    24     android:visibility="gone"
    25     />
    26 <Button
    27     android:id="@+id/myButton"
    28     android:layout_width="wrap_content"
    29     android:layout_height="wrap_content"
    30     android:text="begin"
    31     />
    32 </LinearLayout>

    2.java
    (1)ProgressBarTest.java

     1 package mars.progressbar;
     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 public class ProgressBarTest extends Activity {
    11     /** Called when the activity is first created. */
    12     //声明变量
    13     private ProgressBar firstBar =null;
    14     private ProgressBar secondBar = null;
    15     private Button myButton = null;
    16     private int i = 0 ;
    17     @Override
    18     public void onCreate(Bundle savedInstanceState) {
    19         super.onCreate(savedInstanceState);
    20         setContentView(R.layout.main);
    21         //根据控件的ID来取得代表控件的对象
    22         firstBar = (ProgressBar)findViewById(R.id.firstBar);
    23         secondBar = (ProgressBar)findViewById(R.id.secondBar);
    24         myButton = (Button)findViewById(R.id.myButton);
    25         myButton.setOnClickListener(new ButtonListener());
    26     }
    27     class ButtonListener implements OnClickListener{
    28         
    29         @Override
    30         public void onClick(View v) {
    31             if(i == 0)
    32             {
    33                 //设置进度条处于可见的状态
    34                 firstBar.setVisibility(View.VISIBLE);
    35                 firstBar.setMax(150);
    36                 secondBar.setVisibility(View.VISIBLE);
    37             }
    38             else if ( i < firstBar.getMax()){
    39                 //设置主进度条的当前值
    40                 firstBar.setProgress(i);
    41                 //设置第二进度条的当前值
    42                 firstBar.setSecondaryProgress(i + 10);
    43                 //因为默认的进度条无法显示进行的状态
    44                 //secondBar.setProgress(i);
    45                 
    46             }
    47             else{
    48                 //设置进度条处于不可见状态
    49                 firstBar.setVisibility(View.GONE);
    50                 secondBar.setVisibility(View.GONE);
    51             }
    52             i = i + 10 ;
    53         }
    54         
    55     }
    56     
    57 }

     

  • 相关阅读:
    shell编程
    git
    Flask-SQLAlchemy
    pipreqs
    命令行操作flask
    SQLAlchemy中scoped_session实现线程安全
    打印信息
    键盘事件
    安卓手机APP压力monkey测试
    手机APP功能测试经验分享2016.06.06
  • 原文地址:https://www.cnblogs.com/shamgod/p/5188063.html
Copyright © 2011-2022 走看看