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

Android UI控件之ProgressBar進度條

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

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

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

依照慣例,先上效果圖:

第一張:

第二張:

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

具體實現(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="簡單進度條的展示"  
    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();// 得到底層當前進度值 
      // 以下代碼實現(xiàn)進度值越來越大,越來越小的一個動態(tài)效果 
      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(); 
      } 
    } 
 
  } 
} 

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

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論