Android實(shí)戰(zhàn)教程第二篇之簡(jiǎn)單實(shí)現(xiàn)兩種進(jìn)度條效果
本文實(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í)有所幫助,也希望大家多多支持腳本之家。
- Android自定義View基礎(chǔ)開(kāi)發(fā)之圖片加載進(jìn)度條
- Android實(shí)現(xiàn)自定義圓形進(jìn)度條
- Android實(shí)現(xiàn)支持進(jìn)度條顯示的短信備份工具類
- Android ProgressBar進(jìn)度條使用詳解
- Android ProgressDialog進(jìn)度條使用詳解
- Android帶進(jìn)度的圓形進(jìn)度條
- android自定義進(jìn)度條漸變色View的實(shí)例代碼
- Android中實(shí)現(xiàn)Webview頂部帶進(jìn)度條的方法
- Android 七種進(jìn)度條的樣式
- Android文件下載進(jìn)度條的實(shí)現(xiàn)代碼
相關(guān)文章
Android開(kāi)發(fā)跳轉(zhuǎn)應(yīng)用市場(chǎng)進(jìn)行版本更新功能實(shí)現(xiàn)
這篇文章主要為大家介紹了Android實(shí)現(xiàn)跳轉(zhuǎn)到應(yīng)用市場(chǎng)進(jìn)行版本更新功能,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-04-04Android中多行文本末尾添加圖片排版問(wèn)題的解決方法
這篇文章主要給大家介紹了關(guān)于Android中多行文本末尾添加圖片排版問(wèn)題的解決方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-07-07Android EditText實(shí)現(xiàn)分割輸入內(nèi)容
這篇文章主要為大家詳細(xì)介紹了Android EditText實(shí)現(xiàn)分割輸入內(nèi)容的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04Android代碼檢查規(guī)則Lint的自定義與應(yīng)用詳解
本文主要介紹了Android代碼檢查規(guī)則Lint的自定義與應(yīng)用詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04基于Flutter實(shí)現(xiàn)多邊形和多角星組件
開(kāi)發(fā)中,免不了會(huì)用到多邊形、多角星等圖案,比較常用的多邊形比如雷達(dá)圖、多角星比如評(píng)價(jià)星級(jí)的五角星等,本文章就使用Flutter繪制封裝一個(gè)這樣的組件,需要的可以參考一下2022-05-05Android仿QQ復(fù)制昵稱效果的實(shí)現(xiàn)方法
這篇文章主要介紹了Android仿QQ復(fù)制昵稱效果的實(shí)現(xiàn)方法,主要依賴的是一個(gè)開(kāi)源項(xiàng)目,需要的朋友可以參考下2019-05-05Android Studio的安裝及第一次啟動(dòng)時(shí)的配置問(wèn)題
這篇文章主要介紹了Android Studio的安裝及第一次啟動(dòng)時(shí)的配置,需要的朋友可以參考下2019-09-09Android仿微信文章懸浮窗效果的實(shí)現(xiàn)代碼
這篇文章主要介紹了Android仿微信文章懸浮窗效果的實(shí)現(xiàn)代碼,需要的朋友可以參考下2018-10-10Android使用ViewPager實(shí)現(xiàn)無(wú)限滑動(dòng)效果
相信在大家開(kāi)發(fā)Android的時(shí)候,我們常常用ViewPager來(lái)為自己的應(yīng)用創(chuàng)建廣告條幅,并且常常會(huì)遇到ViewPager無(wú)限滑動(dòng)這樣的需求。下面來(lái)一起看看吧。2016-09-09Android實(shí)現(xiàn)雙擊TitleBar回頂部的功能示例代碼
一個(gè)簡(jiǎn)單易用的導(dǎo)航欄TitleBar,可以輕松實(shí)現(xiàn)IOS導(dǎo)航欄的各種效果,下面這篇文章主要給大家介紹了關(guān)于Android如何實(shí)現(xiàn)雙擊TitleBar回頂部功能的相關(guān)資料,文中給出了詳細(xì)的示例代碼,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-09-09