ProgressBar三種style


 

一、普通的ProgressBar
顯示如圖

<ProgressBar
        android:id="@+id/pbNormal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

二、有進度的ProgressBar

 

 

xml:設置style,Horizontal
<ProgressBar android:id="@+id/progress" android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/Widget.AppCompat.ProgressBar.Horizontal" />
設置進度java文件
        final ProgressBar bar= (ProgressBar) findViewById(R.id.progress); final TextView textView= (TextView) findViewById(R.id.tvProgress); new Thread(){ @Override public void run() { int i=0; while(i<100){ i++; try { Thread.sleep(80); } catch (InterruptedException e) { e.printStackTrace(); } final int j=i; bar.setProgress(i); runOnUiThread(new Runnable() { @Override public void run() { textView.setText(j+"%"); } }); } } }.start();
鏈接:https://www.jianshu.com/p/3e3bcadf90ea
三、自定義有進度ProgressBar
 
progressBar進度條有兩個部分組成, 背景圖形加載進度圖形,使用 <layer-list>標簽,分別用 backgroundprogress作為兩個部分的id值, 背景圖形使用 <shape>加載進度圖形還需要用 <clip>標簽對圖形 <shape>標簽進行包裹;

 

res下的drawable文件夾下,創建樣式
custom_progress.xml
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@android:id/background"> <shape android:shape="rectangle"> <corners android:radius="5dp"/> <gradient android:startColor="#fff" android:endColor="#fff"/> </shape> </item> <item android:id="@android:id/progress"> <clip><!--可裁剪對象--> <shape android:shape="rectangle"> <corners android:radius="5dp"/> <gradient android:angle="45" android:startColor="#f00" android:endColor="#f90"/> </shape> </clip> </item> </layer-list> 
布局xml,需要指定ProgressBar的style
    <ProgressBar android:id="@+id/progressSelf" android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/Widget.AppCompat.ProgressBar.Horizontal" android:progressDrawable="@drawable/custom_progress" /> <TextView android:id="@+id/tvProgress" android:layout_width="wrap_content" android:layout_height="wrap_content" /> 
設置進度java文件
        final ProgressBar bar = (ProgressBar) findViewById(R.id.progressSelf); final TextView textView= (TextView) findViewById(R.id.tvProgress); new Thread(){ @Override public void run() { int i=0; while(i<100){ i++; try { Thread.sleep(80); } catch (InterruptedException e) { e.printStackTrace(); } final int j=i; bar.setProgress(i); runOnUiThread(new Runnable() { @Override public void run() { textView.setText(j+"%"); } }); } } }.start(); 


鏈接:https://www.jianshu.com/p/3e3bcadf90ea
 
 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM