国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android實戰教程第二篇之簡單實現兩種進度條效果

2019-12-12 04:43:52
字體:
來源:轉載
供稿:網友

本文實例實現點擊按鈕模擬進度條下載進度,“下載”完成進度條消失,供大家參考,具體內容如下

代碼如下:
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);   //根據控件的ID來取得代表控件的對象   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)    {     //設置進度條處于可見的狀態     firstBar.setVisibility(View.VISIBLE);     firstBar.setMax(150);//手動設置最大值,默認是100     secondBar.setVisibility(View.VISIBLE);    }    else if ( i < firstBar.getMax()){     //設置主進度條的當前值     firstBar.setProgress(i);     //設置第二進度條的當前值     firstBar.setSecondaryProgress(i + 10);     //因為默認的進度條無法顯示進行的狀態     //secondBar.setProgress(i);         }    else{     //設置進度條處于不可見狀態     firstBar.setVisibility(View.GONE);     secondBar.setVisibility(View.GONE);    }    i = i + 10 ;   }     }   }

 以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 漯河市| 清水县| 武平县| 乐安县| 分宜县| 博野县| 军事| 修水县| 文登市| 皋兰县| 朝阳市| 嵩明县| 五原县| 京山县| 乐平市| 忻州市| 平阴县| 靖远县| 珠海市| 大埔区| 开封市| 新兴县| 克山县| 西充县| 乌拉特前旗| 龙州县| 平顺县| 河南省| 方正县| 泸水县| 望城县| 韶关市| 图木舒克市| 枣强县| 濮阳市| 新泰市| 健康| 宜兴市| 遂溪县| 兴隆县| 开封县|