欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實(shí)戰(zhàn)教程第二篇之簡(jiǎn)單實(shí)現(xiàn)兩種進(jìn)度條效果

 更新時(shí)間:2016年11月10日 11:05:52   作者:楊道龍  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)戰(zhàn)教程第二篇,簡(jiǎn)單實(shí)現(xiàn)兩種進(jìn)度條效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例實(shí)現(xiàn)點(diǎn)擊按鈕模擬進(jìn)度條下載進(jìn)度,“下載”完成進(jìn)度條消失,供大家參考,具體內(nèi)容如下

代碼如下:
xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:orientation="vertical" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 > 
<TextView 
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content" 
 android:text="@string/hello" 
 /> 
<ProgressBar 
 android:id="@+id/firstBar" 
 style="?android:attr/progressBarStyleHorizontal" 
 android:layout_width="200dp" 
 android:layout_height="wrap_content" 
 android:visibility="gone" 
 /> 
<ProgressBar 
 android:id="@+id/secondBar" 
 style="?android:attr/progressBarStyle" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:visibility="gone" 
 /> 
<Button 
 android:id="@+id/myButton" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:text="begin" 
 /> 
</LinearLayout> 

Activity:

package ydl.progressbar; 
 
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; 
 
public class ProgressBarTest extends Activity { 
 /** Called when the activity is first created. */ 
 //聲明變量 
 private ProgressBar firstBar =null; 
 private ProgressBar secondBar = null; 
 private Button myButton = null; 
 private int i = 0 ; 
 @Override 
 public void onCreate(Bundle savedInstanceState) { 
  super.onCreate(savedInstanceState); 
  setContentView(R.layout.main); 
  //根據(jù)控件的ID來(lái)取得代表控件的對(duì)象 
  firstBar = (ProgressBar)findViewById(R.id.firstBar); 
  secondBar = (ProgressBar)findViewById(R.id.secondBar); 
  myButton = (Button)findViewById(R.id.myButton); 
  myButton.setOnClickListener(new ButtonListener()); 
 } 
 class ButtonListener implements OnClickListener{ 
   
  @Override 
  public void onClick(View v) { 
   if(i == 0) 
   { 
    //設(shè)置進(jìn)度條處于可見(jiàn)的狀態(tài) 
    firstBar.setVisibility(View.VISIBLE); 
    firstBar.setMax(150);//手動(dòng)設(shè)置最大值,默認(rèn)是100 
    secondBar.setVisibility(View.VISIBLE); 
   } 
   else if ( i < firstBar.getMax()){ 
    //設(shè)置主進(jìn)度條的當(dāng)前值 
    firstBar.setProgress(i); 
    //設(shè)置第二進(jìn)度條的當(dāng)前值 
    firstBar.setSecondaryProgress(i + 10); 
    //因?yàn)槟J(rèn)的進(jìn)度條無(wú)法顯示進(jìn)行的狀態(tài) 
    //secondBar.setProgress(i); 
     
   } 
   else{ 
    //設(shè)置進(jìn)度條處于不可見(jiàn)狀態(tài) 
    firstBar.setVisibility(View.GONE); 
    secondBar.setVisibility(View.GONE); 
   } 
   i = i + 10 ; 
  } 
   
 } 
  
}

 以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論