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

首頁 > 系統 > Android > 正文

Android實戰教程之實現兩種進度條的效果

2020-02-21 17:29:59
字體:
來源:轉載
供稿:網友

Android開發中要如何實現進度條效果,其實這個實現方法很簡單,本文是武林技術頻道小編為大家帶來的Android實戰教程之實現兩種進度條的效果,一起跟著小編的步伐來看看吧!

代碼如下:
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 ;   }     }   }

關于Android實戰教程之實現兩種進度條的效果的話題武林技術頻道小編就說到這里了,看完這篇文章你是不是有一個深刻的了解呢。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 北碚区| 平凉市| 卢龙县| 从江县| 双牌县| 德钦县| 神木县| 桃江县| 新晃| 柳河县| 乌拉特后旗| 布尔津县| 上犹县| 方城县| 潮州市| 聂荣县| 湖南省| 邛崃市| 漳平市| 扎鲁特旗| 福海县| 汕尾市| 金山区| 开江县| 法库县| 巨野县| 绵竹市| 湟源县| 阿城市| 四会市| 西林县| 余江县| 湖南省| 南京市| 奈曼旗| 丹巴县| 青铜峡市| 韶山市| 萨嘎县| 云阳县| 康保县|