自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Openharmony應用開發(fā)--健康飲食APP分解

系統(tǒng) OpenHarmony
我把飲食APP界面各各組件分開文件來寫,然后再引用組裝,對于初學者,把每個組件都單獨弄懂了,然后再通過下面的導圖,就清晰的組裝成一個完整APP。

??想了解更多關于開源的內(nèi)容,請訪問:??

??51CTO 開源基礎軟件社區(qū)??

??https://ost.51cto.com??

前言

此處健康生活實戰(zhàn)課程,個人覺得非常值得學習,里面普及到的ArkUI知識點很多,從中學到常見基礎組件的使用和頁面布局、自定義組件使用、屬性動畫,顯示動畫、轉場動畫、綁定手勢方法、圖表繪制、狀態(tài)變量、國際化、一次開發(fā)多端部署等等知識,我把飲食APP界面各各組件分開文件來寫,然后再引用組裝,對于初學者,把每個組件都單獨弄懂了,然后再通過下面的導圖,就清晰的組裝成一個完整APP。

#打卡不停更#健康飲食APP分解-開源基礎軟件社區(qū)

效果圖

清晰效果圖請移步到B站觀看https://www.bilibili.com/video/BV1de4y1n7qc/?spm_id_from=333.999.0.0。

#打卡不停更#健康飲食APP分解-開源基礎軟件社區(qū)

項目結構圖

#打卡不停更#健康飲食APP分解-開源基礎軟件社區(qū)#打卡不停更#健康飲食APP分解-開源基礎軟件社區(qū)

開發(fā)流程

先從簡單組件開始,從也是視頻里的課后作業(yè),當自己一個個簡單的組件做出來了,組成一個完整APP也就不難了,這里我以記錄飲食對話框開始,對話框有用餐時間,比如早餐、午餐、晚餐、宵夜,有用餐食物重量,而用餐時間是固定的,可以在資源文件定義好國際化,然后在組件上引用。資源文件定義用餐Label,使用的是字符串數(shù)組strarray.json來定義。

{
"strarray": [
{
"name": "mealTime_labels",
"value": [
{
"value": "Breakfast"
},
{
"value": "Lunch"
},
{
"value": "Dinner"
},
{
"value": "Supper"
}
]
}
]
}
{
"strarray": [
{
"name": "mealTime_labels",
"value": [
{
"value": "早餐"
},
{
"value": "午餐"
},
{
"value": "晚餐"
},
{
"value": "宵夜"
}
]
}
]
}

關鍵代碼:

@CustomDialog
export struct Record {
private foodInfo: FoodInfo
private controller: CustomDialogController
private select: number = 1
private mileTime: Resource = $r('app.strarray.mealTime_labels')
private foodWeight: string[] = ['25', '50', '100', '150', '200', '250', '300', '350', '400', '450', '500']
private mealTimeId: MealTimeEnum = MealTimeEnum.Lunch
private mealWeight: number = Number(this.foodWeight[this.select])
build() {
Column() {
Row({ space: 6 }) {
Column() {
Text(this.foodInfo.name)
.minFontSize(18)
.maxFontSize(30)
.maxLines(1)
Text($r('app.string.calorie_with_kcal_unit', this.foodInfo.calories.toString()))
.fontSize(16)
.fontColor('rgba(0,0,0,0.4)')
.margin({ top: 2 })
}
.layoutWeight(1)
.justifyContent(FlexAlign.Center)

TextPicker({ range: this.mileTime, selected: this.select })
.layoutWeight(1)
.linearGradient({
angle: 0,
direction: GradientDirection.Top,
colors: [[0xfdfdfd, 0.0], [0xe0e0e0, 0.5], [0xfdfdfd, 1]],
})
.onChange((value: string, index: number) => {
this.mealTimeId = index
})

TextPicker({ range: this.foodWeight, selected: this.select })
.layoutWeight(1)
.linearGradient({
angle: 0,
direction: GradientDirection.Top,
colors: [[0xfdfdfd, 0.0], [0xe0e0e0, 0.5], [0xfdfdfd, 1]],
})
.onChange((value: string) => {
this.mealWeight = Number(value)
})
}
.height(128)
Button($r('app.string.button_food_detail_complete'), { type: ButtonType.Capsule, stateEffect: true })
.height(43)
.width('100%')
.margin({ top: 33, left: 72, right: 72 })
.backgroundColor($r('app.color.theme_color_green'))
.onClick(() => {
let dietRecordsList = AppStorage.Get<Array<DietRecord>>('dietRecords')
if (dietRecordsList == undefined || dietRecordsList.length === 0) {
dietRecordsList = new Array<DietRecord>()
}
let dietRecordData = new DietRecord(dietRecordsList.length, this.foodInfo.id, new MealTime(this.mealTimeId), this.mealWeight)
dietRecordsList.push(dietRecordData)
AppStorage.SetOrCreate<Array<DietRecord>>('dietRecords', dietRecordsList)
this.controller.close()
})
}
.cardStyle()
.height(254)
.width('90%')
}
}

對話框效果圖。

#打卡不停更#健康飲食APP分解-開源基礎軟件社區(qū)
#打卡不停更#健康飲食APP分解-開源基礎軟件社區(qū)

總結

根據(jù)導圖列出的各組件,像寫對話框一樣,一個個組件功能完成,對于初始者來說,一下子寫一個小組件,比一開始就寫一個Demo簡單多了,組件寫多了,經(jīng)驗豐富了,那時要寫什么樣的APP,就看個人創(chuàng)意了,我也打算,下來有空把這個飲食APP用到的各組件,每個組件寫一個帖子,把用到的知識都總結出來,這樣對以后的學習也有一定的幫助,謝謝這次活動的實例,讓我學到了更多的知識,我也會一直在學習路上。

??想了解更多關于開源的內(nèi)容,請訪問:??

??51CTO 開源基礎軟件社區(qū)??

??https://ost.51cto.com??。

責任編輯:jianghua 來源: 51CTO開源基礎軟件社區(qū)
相關推薦

2022-10-09 15:13:18

TextPickerArkUI eTS

2022-10-10 14:51:51

ArkUI eTSPieChart組件

2021-07-22 08:45:47

鴻蒙HarmonyOS應用

2018-01-24 17:05:54

戴爾IT基礎建設飲食健康

2022-03-02 16:08:31

Harmony應用開發(fā)鴻蒙

2023-12-26 08:21:18

夸克App大模型

2022-11-04 14:58:59

應用開發(fā)鴻蒙

2022-10-08 16:19:40

智能喂食器鴻蒙

2023-08-17 15:04:22

2022-11-02 15:49:45

應用開發(fā)鴻蒙

2022-11-11 09:37:58

數(shù)據(jù)轉碼應用開發(fā)

2022-11-07 15:40:22

數(shù)據(jù)轉碼應用應用開發(fā)

2022-02-15 14:06:36

OpenHarmon操作系統(tǒng)鴻蒙

2023-03-09 15:10:49

應用開發(fā)鴻蒙

2022-08-06 08:34:04

京東App適配技術棧

2023-04-07 09:20:55

2023-08-10 17:14:52

鴻蒙自定義彈窗

2023-07-31 17:35:31

ArkTS鴻蒙

2022-02-15 14:45:14

OpenHarmo系統(tǒng)鴻蒙

2023-08-07 15:23:28

鴻蒙首次啟動申請授權
點贊
收藏

51CTO技術棧公眾號