| 屬性 | 含義 | 適用場景 | 視覺表現 |
|---|---|---|---|
ProgressDrawable |
確定進度繪製對象 | 文件下載、安裝進度、數據加載等可量化進度場景 | 水平進度條、環形進度條,顯示具體百分比 |
IndeterminateDrawable |
不確定進度繪製對象 | 網絡請求等待、數據庫查詢、初始化加載等無法預估耗時場景 | 旋轉圓環、脈衝動畫、橫向滑動條,僅提示「正在進行」 |
<ProgressBar
android:id="@+id/pb_download"
style="@android:style/Widget.ProgressBar.Horizontal"
android:progressDrawable="@drawable/custom_progress_horizontal"
android:max="100"
android:progress="0" />
動態更新:pb.setProgress((int)(downloaded * 100 / total));
<ProgressBar
android:id="@+id/pb_loading"
android:indeterminateDrawable="@drawable/custom_progress_circular"
android:indeterminate="true" />
無需設置 progress,動畫自動循環。
onLevelChange 響應 level 變化;不確定進度需定義 AnimationDrawable 幀動畫。ProgressIndicator (Material Components 庫) 統一風格。