零基礎學鴻蒙程式設計-UI控制元件_ProgressBar

什麼是ProgressBar

ProgressBar是用於展示進度的UI控制元件,。

1。橫向進度

效果圖

零基礎學鴻蒙程式設計-UI控制元件_ProgressBar

程式碼

2。縱向進度

效果圖

零基礎學鴻蒙程式設計-UI控制元件_ProgressBar

程式碼

3。橫向分段展示進度

效果圖

零基礎學鴻蒙程式設計-UI控制元件_ProgressBar

程式碼

4。橫向進度條展示+文字

效果圖

零基礎學鴻蒙程式設計-UI控制元件_ProgressBar

程式碼

基礎樣例完整原始碼

https://gitee。com/hspbc/harmonyos_demos/tree/master/progressBarDemo

常用屬性說明

屬性名

用途

ohos:width

設定控制元件寬度,可設定為:match_parent(和父控制元件一樣),match_content(按照內容自動伸縮),設定固定值(如200vp)

ohos:height

設定控制元件高度,可設定為:match_parent(和父控制元件一樣),match_content(按照內容自動伸縮),設定固定值(如200vp)

ohos:layout_alignment

在父控制元件內對齊方式,可選值:left:居左;start:居左;center:居中;right:居右;end:居右

ohos:background_element

設定背景,可以是色值(如#FF0000)或圖片等

ohos:visibility

可選值: visible(顯示), invisible(隱藏,但是仍佔據UI空間),hide(隱藏,且不佔UI空間)

ohos:progress

設定當前進度

ohos:max

設定最大進度值

ohos:min

設定最小進度值

ohos:orientation

設定展示方向,預設橫向,可選值:vertical:縱向;horizontal:橫向

ohos:progress_element

設定進度條顏色,樣例:ohos:progress_element=“#FF8800”

ohos:divider_lines_enabled

設定是否顯示分段,可選值:true:顯示分段;false:不顯示

ohos:divider_lines_number

設定分段數量

ohos:progress_width

設定進度條的寬度,樣例:ohos:progress_width=“5vp”

ohos:progress_hint_text

設定進度條上文字,樣例:ohos:progress_hint_text=“30%”

ohos:progress_hint_text_color

設定進度條上文字顏色,樣例:ohos:progress_hint_text_color=“#000000”

更多屬性及實際效果,可以在開發工具裡自行體驗。