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

首頁 > 系統 > Android > 正文

Android UI控件之ProgressBar進度條

2019-10-22 18:19:42
字體:
來源:轉載
供稿:網友

我們知道在所有的界面UI中進度條無疑是非常重要的一個,因為它可以給用戶一個較為清晰的視覺效果:就是用戶的操作的完成情況.這不是簡單的完成與未完成,而是以一個進度的方式展示給用戶的交互性更強了。

對于Android系統中的進度條如何使用呢?下一是簡單的實現,并未做相關的美化處理。

依照慣例,先上效果圖:

第一張:

第二張:

其中兩個原型的進度條并未做任何的處理,水平進度條利用線程使之不停地增加減少。

具體實現首先看布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   xmlns:tools="http://schemas.android.com/tools"   android:layout_width="match_parent"   android:layout_height="match_parent"   android:orientation="vertical">    <TextView     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="簡單進度條的展示"      android:layout_gravity="center_horizontal"/>    <ProgressBar     android:id="@+id/progressBar1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"      android:layout_gravity="center_horizontal"     />    <ProgressBar     android:id="@+id/progressBar2"     style="?android:attr/progressBarStyleLarge"     android:layout_width="wrap_content"     android:layout_height="wrap_content"       android:layout_gravity="center_horizontal"/>    <ProgressBar     android:id="@+id/progressBar3"     style="?android:attr/progressBarStyleHorizontal"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_gravity="center_horizontal"      android:max="100"     android:minWidth="180dip"     android:minHeight="40dip"     />  </LinearLayout> 

之后是MainActivity

package com.kiritor.ui_progressbar;  import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.ProgressBar;  public class MainActivity extends Activity implements Runnable {    private ProgressBar bar = null;   private Thread thread = null;// 聲明一個線程   private boolean stateChange;    @Override   protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_main);     bar = (ProgressBar) findViewById(R.id.progressBar3);     thread = new Thread(this);     thread.start();   }    @Override   public boolean onCreateOptionsMenu(Menu menu) {     // Inflate the menu; this adds items to the action bar if it is present.     getMenuInflater().inflate(R.menu.main, menu);     return true;   }    @Override   public void run() {     while (true) {       int current = bar.getProgress();// 得到當前進度值       int currentMax = bar.getMax();// 得到進度條的最大進度值       //int secCurrent = bar.getSecondaryProgress();// 得到底層當前進度值       // 以下代碼實現進度值越來越大,越來越小的一個動態效果       if (stateChange == false) {         if (current >= currentMax) {           stateChange = true;         } else {           // 設置進度值           bar.setProgress(current + 1);           // 設置底層進度值           bar.setSecondaryProgress(current + 1);         }       } else {         if (current <= 0) {           stateChange = false;         } else {           bar.setProgress(current - 1);           bar.setSecondaryProgress(current - 1);         }       }       try {         Thread.sleep(50);       } catch (InterruptedException e) {         // TODO Auto-generated catch block         e.printStackTrace();       }     }    } } 

以上就是進度條的簡單的用法,之后筆者會實現一些“特別”進度條,漂亮的,另類的!代碼較為簡單就不給源碼了Over!

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


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 涡阳县| 泾川县| 泰宁县| 互助| 西青区| 醴陵市| 平遥县| 哈密市| 阜新市| 衡南县| 通许县| 南汇区| 离岛区| 牟定县| 政和县| 盱眙县| 山阳县| 宣武区| 米易县| 高陵县| 吉木萨尔县| 阳谷县| 德庆县| 民勤县| 庆元县| 新安县| 讷河市| 静安区| 靖江市| 阿克苏市| 潜山县| 邯郸市| 广南县| 辉南县| 保亭| 温泉县| 宁夏| 金寨县| 南阳市| 南阳市| 长子县|