【鸿蒙】鸿蒙App应用-《校园通》开发步骤

本文介绍了如何使用Java语言在HarmonyOS平台上开发《校园通》应用,涵盖学校生活、出行指南、游玩南昌和号码百事通四大功能模块。详细讲述了从创建主界面、设置布局到实现页面跳转的步骤,并提供了运行效果展示。此外,还提到了HarmonyOS环境的搭建和DevEcoStudio的配置方法。
摘要由CSDN通过智能技术生成

1. 介绍

《校园通》软件很多系统中都有,android,ios,平板电脑等,该软件主要用于学校里的环境,学生,老师之间的沟通,方便学生的行动。

实现思路:

  1. 创建一个Java语言的鸿蒙项目
  2. 创建主界面,包含:学校生活,出行指南,游玩南昌,号码百事通等四大模块
  3. 学校生活:校区平面图,校园风景,学生指南,返回等功能
  4. 游玩南昌:滕王阁,八大山人纪念馆,西山万寿宫,梅岭等风景点简介
  5. 号码百事通:学生可查询学校的院系信息,教师信息,订餐信息等
  6. 出行指南:这里调用高德地图开发者平台的第三方类库,完成我的位置,线路查询,位置查询等功能

2. 搭建HarmonyOS环境

我们首先需要完成HarmonyOS开发环境搭建,可参照如下步骤进行。

  • 安装DevEco Studio,详情请参考下载和安装软件
  • 设置DevEco Studio开发环境,DevEco Studio开发环境依赖于网络环境,需要连接上网络才能确保工具的正常使用,可以根据如下两种情况来配置开发环境:
    1. 如果可以直接访问Internet,只需进行下载HarmonyOS SDK操作。
    2. 如果网络不能直接访问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.【鸿蒙】《校园通》--号码百事通模块

项目源码地址

  • 7
    点赞
  • 38
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

笔触狂放

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值