ANDROID_MARS學習筆記_S01原始版_005_ProgressBar

來源:互聯網
上載者:User

標籤:

一、代碼

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 <ProgressBar13     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 <ProgressBar20     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 <Button27     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     @Override18     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         @Override30         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 }

 

 

 

ANDROID_MARS學習筆記_S01原始版_005_ProgressBar

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.