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

Android UI控件之ProgressBar進(jìn)度條

 更新時(shí)間:2017年12月19日 09:38:39   作者:LCore  
這篇文章主要為大家詳細(xì)介紹了Android UI控件之ProgressBar進(jìn)度條的實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

我們知道在所有的界面UI中進(jìn)度條無疑是非常重要的一個(gè),因?yàn)樗梢越o用戶一個(gè)較為清晰的視覺效果:就是用戶的操作的完成情況.這不是簡(jiǎn)單的完成與未完成,而是以一個(gè)進(jìn)度的方式展示給用戶的交互性更強(qiáng)了。

對(duì)于Android系統(tǒng)中的進(jìn)度條如何使用呢?下一是簡(jiǎn)單的實(shí)現(xiàn),并未做相關(guān)的美化處理。

依照慣例,先上效果圖:

第一張:

第二張:

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

具體實(shí)現(xiàn)首先看布局文件:

<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="簡(jiǎn)單進(jìn)度條的展示"  
    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;// 聲明一個(gè)線程 
  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();// 得到當(dāng)前進(jìn)度值 
      int currentMax = bar.getMax();// 得到進(jìn)度條的最大進(jìn)度值 
      //int secCurrent = bar.getSecondaryProgress();// 得到底層當(dāng)前進(jìn)度值 
      // 以下代碼實(shí)現(xiàn)進(jìn)度值越來越大,越來越小的一個(gè)動(dòng)態(tài)效果 
      if (stateChange == false) { 
        if (current >= currentMax) { 
          stateChange = true; 
        } else { 
          // 設(shè)置進(jìn)度值 
          bar.setProgress(current + 1); 
          // 設(shè)置底層進(jìn)度值 
          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(); 
      } 
    } 
 
  } 
} 

以上就是進(jìn)度條的簡(jiǎn)單的用法,之后筆者會(huì)實(shí)現(xiàn)一些“特別”進(jìn)度條,漂亮的,另類的!代碼較為簡(jiǎn)單就不給源碼了Over!

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

相關(guān)文章

最新評(píng)論