自學(xué)鴻蒙應(yīng)用開發(fā)(14)- RoundProgressBar
本文介紹在鴻蒙應(yīng)用中RoundProgressBar組件的基本用法。
增加RoundProgressBar組件
如下代碼中35行~44行所示,在布局中增加RoundProgressBar組件。
<DirectionalLayoutxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:height="match_parent"ohos:width="match_parent"ohos:orientation="vertical"><Componentohos:height="0vp"ohos:weight="3"ohos:width="match_parent"/><DirectionalLayoutxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:height="match_content"ohos:width="match_parent"ohos:layout_alignment="center"ohos:orientation="vertical"><Imageohos:id="$+id:image"ohos:width="match_content"ohos:height="match_content"ohos:layout_alignment="center"ohos:image_src="$media:DevEco"/><TimePickerohos:id="$+id:time_picker"ohos:24_hour_mode="false"ohos:height="match_content"ohos:width="match_parent"ohos:layout_alignment="horizontal_center"ohos:text_am="AM"ohos:text_pm="PM"ohos:normal_text_size="20fp"ohos:selected_text_size="25fp"/><RoundProgressBarohos:id="$+id:second_progress"ohos:height="200vp"ohos:width="200vp"ohos:layout_alignment="horizontal_center"ohos:progress_width="20vp"ohos:start_angle="45"ohos:max_angle="270"ohos:progress="20"ohos:progress_color="#47CC47"/>DirectionalLayout><Componentohos:height="0vp"ohos:weight="5"ohos:width="match_parent"/>DirectionalLayout>
代碼中組件id被指定為second_progress,會在下面的響應(yīng)代碼中用到。
在代碼中使用RoundProgressBar組件
下面代碼中的第18行獲取RoundProgressBar組件后,在第19行根據(jù)TimePicker的狀態(tài)更新RoundProgressBar的值,然后在第26行TimerPicker的響應(yīng)處理中,同樣是根據(jù)TimePicker的狀態(tài)更新ProgressBar的值。
package com.example.helloharmony.slice;import com.example.helloharmony.ResourceTable;import ohos.aafwk.ability.AbilitySlice;import ohos.aafwk.content.Intent;import ohos.agp.components.*;import ohos.agp.window.dialog.ToastDialog;import java.time.LocalTime;import java.time.temporal.ChronoUnit;public class ComponentAbilitySlice extends AbilitySlice {public void onStart(Intent intent) {super.onStart(intent);super.setUIContent(ResourceTable.Layout_ability_component);//獲取TimePicker組件TimePicker picker = (TimePicker) findComponentById(ResourceTable.Id_time_picker);//獲取ProgressBar組件RoundProgressBar secondsBar = (RoundProgressBar)findComponentById(ResourceTable.Id_second_progress);updateProgressValue(picker, secondsBar);//為TimePicker設(shè)定事件響應(yīng)ComponentAbilitySlice this_slice = this;picker.setTimeChangedListener(new TimePicker.TimeChangedListener() {public void onTimeChanged(TimePicker timePicker, int hour, int minute, int second) {this_slice.updateProgressValue(timePicker, secondsBar);}});}public void onActive() {super.onActive();}public void onForeground(Intent intent) {super.onForeground(intent);}private void updateProgressValue(TimePicker time_picker, ProgressBar progress){int seconds = (time_picker.getHour() * 60 + time_picker.getMinute()) * 60 + time_picker.getSecond();progress.setProgressValue(progress.getMin() + seconds * (progress.getMax() - progress.getMin()) / 86400);}}
畫面顯示如下:
參考文檔
RoundProgressBar組件
https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ui-java-component-roundprogressbar-0000001062558057
RoundProgressBar類
https://developer.harmonyos.com/cn/docs/documentation/doc-references/roundprogressbar-0000001054558721
新書介紹
《實(shí)戰(zhàn)Python設(shè)計(jì)模式》是作者最近出版的新書,拜托多多關(guān)注!

本書利用Python 的標(biāo)準(zhǔn)GUI 工具包tkinter,通過可執(zhí)行的示例對23 個設(shè)計(jì)模式逐個進(jìn)行說明。這樣一方面可以使讀者了解真實(shí)的軟件開發(fā)工作中每個設(shè)計(jì)模式的運(yùn)用場景和想要解決的問題;另一方面通過對這些問題的解決過程進(jìn)行說明,讓讀者明白在編寫代碼時如何判斷使用設(shè)計(jì)模式的利弊,并合理運(yùn)用設(shè)計(jì)模式。
對設(shè)計(jì)模式感興趣而且希望隨學(xué)隨用的讀者通過本書可以快速跨越從理解到運(yùn)用的門檻;希望學(xué)習(xí)Python GUI 編程的讀者可以將本書中的示例作為設(shè)計(jì)和開發(fā)的參考;使用Python 語言進(jìn)行圖像分析、數(shù)據(jù)處理工作的讀者可以直接以本書中的示例為基礎(chǔ),迅速構(gòu)建自己的系統(tǒng)架構(gòu)。
覺得本文有幫助?請分享給更多人。
關(guān)注微信公眾號【面向?qū)ο笏伎肌枯p松學(xué)習(xí)每一天!
面向?qū)ο箝_發(fā),面向?qū)ο笏伎迹?/span>

