1. 介紹
《校園通》軟體很多系統中都有,android,ios,平板電腦等,該軟體主要用于學校里的環境,學生,老師之間的溝通,方便學生的行動,
實作思路:
- 創建一個Java語言的鴻蒙專案
- 創建主界面,包含:學校生活,出行指南,游玩南昌,號碼百事通等四大模塊
- 學校生活:校區平面圖,校園風景,學生指南,回傳等功能
- 游玩南昌:滕王閣,八大山人紀念館,西山萬壽宮,梅嶺等風景點簡介
- 號碼百事通:學生可查詢學校的院系資訊,教師資訊,訂餐資訊等
- 出行指南:這里呼叫高德地圖開發者平臺的第三方類別庫,完成我的位置,線路查詢,位置查詢等功能
2. 搭建HarmonyOS環境
我們首先需要完成HarmonyOS開發環境搭建,可參照如下步驟進行,
- 安裝DevEco Studio,詳情請參考下載和安裝軟體,
- 設定DevEco Studio開發環境,DevEco Studio開發環境依賴于網路環境,需要連接上網路才能確保工具的正常使用,可以根據如下兩種情況來配置開發環境:
- 如果可以直接訪問Internet,只需進行下載HarmonyOS SDK操作,
- 如果網路不能直接訪問Internet,需要通過代理服務器才可以訪問,請參考配置開發環境,
3. 基本步驟
- 創建MainAbilitySlice的類,并繼承AbilitySlice,實作onStart方法加載布局檔案,
package com.example.campusproject.slice;
import com.example.campusproject.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Image;
public
class MainAbilitySlice extends AbilitySlice {
private Image iv_lt,iv_rt,iv_lb,iv_rb;
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_main);
iv_lb= (Image) this.findComponentById(ResourceTable.Id_iv_lb);
iv_lt= (Image) this.findComponentById(ResourceTable.Id_iv_lt);
iv_rt= (Image) this.findComponentById(ResourceTable.Id_iv_rt);
iv_rb= (Image) this.findComponentById(ResourceTable.Id_iv_rb);
//學校生活
iv_lt.setClickedListener(listener->present(new XXSHAbilitySlice(),
new Intent()));
//出行指南
iv_rt.setClickedListener(listener->present(new CXZNAbilitySlice(),new Intent()));
//游玩南昌
iv_lb.setClickedListener(listener->present(new YWNNAbilitySlice(),new Intent()));
//號碼百事通
iv_rb.setClickedListener(listener->present(new HMBSTAbilitySlice(),new Intent()));
}
@Override
public void onActive() {
super.onActive();
}
@Override
public void onForeground(Intent intent) {
super.onForeground(intent);
}
}
- 在resources->base->layout下創建ability_main.xml布局檔案
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:background_element="$media:bg"
ohos:orientation="vertical">
<DirectionalLayout
ohos:height="100fp"
ohos:weight="1"
ohos:width="match_parent"
ohos:orientation="vertical"
ohos:background_element="#88ffffff"
ohos:alignment="center">
<Text
ohos:height="match_content"
ohos:width="match_parent"
ohos:text_alignment="center"
ohos:text="華為開發者大學"
ohos:text_color="#000"
ohos:text_size="25fp"/>
<Text
ohos:height="match_content"
ohos:width="match_parent"
ohos:text_alignment="center"
ohos:text="Huawei Developer University"
ohos:text_color="#000"
ohos:text_size="18fp"/>
</DirectionalLayout>
<DependentLayout
ohos:weight="3"
ohos:margin="30fp"
ohos:height="match_content"
ohos:width="match_parent">
<Image
ohos:height="80fp"
ohos:width="80fp"
ohos:center_in_parent="true"
ohos:scale_mode="stretch"
ohos:image_src="$media:hw"/>
<Image
ohos:id="$+id:iv_lt"
ohos:align_parent_left="true"
ohos:height="60fp"
ohos:width="100fp"
ohos:scale_mode="stretch"
ohos:image_src="$media:xuexiaoshenghuo"/>
<Image
ohos:id="$+id:iv_rt"
ohos:align_parent_right="true"
ohos:height="60fp"
ohos:width="100fp"
ohos:scale_mode="stretch"
ohos:image_src="$media:chuxingzhinan"/>
<Image
ohos:id="$+id:iv_lb"
ohos:align_parent_left="true"
ohos:align_parent_bottom="true"
ohos:height="60fp"
ohos:width="100fp"
ohos:scale_mode="stretch"
ohos:image_src="$media:youwannanchang"/>
<Image
ohos:id="$+id:iv_rb"
ohos:align_parent_right="true"
ohos:align_parent_bottom="true"
ohos:height="60fp"
ohos:width="100fp"
ohos:scale_mode="stretch"
ohos:image_src="$media:haomabaishitong"/>
</DependentLayout>
<Text
ohos:height="match_content"
ohos:width="match_parent"
ohos:text="構建萬物互聯的智能世界"
ohos:text_color="#000"
ohos:text_size="25fp"
ohos:text_alignment="center"
ohos:weight="2"/>
</DirectionalLayout>
2.運行效果展示

1.【鴻蒙】《校園通》--校園生活模塊
2.【鴻蒙】《校園通》--游玩南昌模塊
3.【鴻蒙】《校園通》--號碼百事通模塊???????
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/291071.html
標籤:其他
下一篇:Flutter 常見問題總結
