【鸿蒙】HarMonyOS的UI组件学习五之面试宝典
2022/10/22 23:24:05
本文主要是介绍【鸿蒙】HarMonyOS的UI组件学习五之面试宝典,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
在生活,学习中每天都要学习,社会中也有许多的各行各业的做题软件,今天分享使用鸿蒙系统开发做题类的应用软件学习,页面比较简单,终点在RadioButton和CheckBox组件的学习以及功能的完成,其效果如下: 先看单选题,使用的是RadioButton组件,但必须要套在RadioContainer组件中才能实现单选效果,并设定选中选项改变字体颜色,将选项填写在小括号内: 在这里插入图片描述 接下来看多选题,这里使用CheckBox组件完成多选功能,将选中的选项填写在小括号内,如果选错了,临时修改答案,也会同步刷新小括号内的选项: 假设取消一个C选项,那么界面效果是如下: 继续取消或者添加选项都是可以进行同步刷新,这里只是学习的小案例,如果你觉得能掌握了,那么你离开发一个完整的题库软件更进一步了,甚至你可以举一反三,根据自己的想法把它做的更好。 接下来我们上代码,先看一下布局的代码:
<?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:orientation="vertical"> <Text ohos:height="match_content" ohos:width="match_parent" ohos:text="面试宝典" ohos:text_size="35vp" ohos:text_color="#fff" ohos:text_alignment="center" ohos:background_element="#FF3333EC"/> <DirectionalLayout ohos:height="match_content" ohos:width="match_parent" ohos:weight="1"> <Text ohos:height="match_content" ohos:width="match_parent" ohos:text="单选题" ohos:text_size="30vp"/> <Text ohos:id="$+id:tv5" ohos:height="match_content" ohos:width="match_parent" ohos:multiple_lines="true" ohos:text="1.下列哪个终端设备系统不是移动互联端的系统的技术?()" ohos:text_size="25vp"/> <RadioContainer ohos:id="$+id:rc_title" ohos:height="match_content" ohos:width="match_parent"> <RadioButton ohos:height="match_content" ohos:width="match_content" ohos:check_element="null" ohos:text="A.Android" ohos:text_color_on="#f00" ohos:text_size="22vp"/> <RadioButton ohos:height="match_content" ohos:width="match_content" ohos:check_element="null" ohos:text="B.IOS" ohos:text_color_on="#f00" ohos:text_size="22vp"/> <RadioButton ohos:height="match_content" ohos:width="match_content" ohos:check_element="null" ohos:text="C.JavaEE" ohos:text_color_on="#f00" ohos:text_size="22vp"/> <RadioButton ohos:height="match_content" ohos:width="match_content" ohos:check_element="null" ohos:text="D.HarMonyOS" ohos:text_color_on="#f00" ohos:text_size="22vp"/> </RadioContainer> </DirectionalLayout> <DirectionalLayout ohos:height="match_content" ohos:width="match_parent" ohos:weight="1"> <Text ohos:height="match_content" ohos:width="match_parent" ohos:text="多选题" ohos:text_size="30vp"/> <Text ohos:id="$+id:tv6" ohos:height="match_content" ohos:width="match_parent" ohos:multiple_lines="true" ohos:text="2.下列哪些是Java面向对象的三大特征?()" ohos:text_size="25vp"/> <Checkbox ohos:id="$+id:cb1" ohos:height="match_content" ohos:width="match_content" ohos:check_element="null" ohos:text="A.封装" ohos:text_color_on="#f00" ohos:text_size="22vp"/> <Checkbox ohos:id="$+id:cb2" ohos:height="match_content" ohos:width="match_content" ohos:check_element="null" ohos:text="B.接口" ohos:text_color_on="#f00" ohos:text_size="22vp"/> <Checkbox ohos:id="$+id:cb3" ohos:height="match_content" ohos:width="match_content" ohos:check_element="null" ohos:text="C.继承" ohos:text_color_on="#f00" ohos:text_size="22vp"/> <Checkbox ohos:id="$+id:cb4" ohos:height="match_content" ohos:width="match_content" ohos:check_element="null" ohos:text="D.多态" ohos:text_color_on="#f00" ohos:text_size="22vp"/> </DirectionalLayout> </DirectionalLayout>
这里整个页面使用的是DirectionalLayout线性布局,里面使用了两个DirectionalLayout线性布局将整个页面平均一份为二,上半部分用于单选题,下半部分用于多选题。 上半部分中使用了两个Text组件显示题目和题型,接着使用了RadioContainer组件包裹了四个RadioButton组件实现单选功能,并给这些单选按钮添加了选中的字体颜色。 下半部分中也是使用了两个Text组件显示题目和题型,接着使用了四个CheckBox组件显示选项。 相信大家已经了解了布局的整个搭建的结构,那现在最主要的就是怎么实现做题的功能,下面上java代码:
这篇关于【鸿蒙】HarMonyOS的UI组件学习五之面试宝典的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-01为什么公共事业机构会偏爱 TiDB :TiDB 数据库在某省妇幼健康管理系统的应用
- 2024-04-26敏捷开发:想要快速交付就必须舍弃产品质量?
- 2024-04-26静态代码分析的这些好处,我竟然都不知道?
- 2024-04-26你在测试金字塔的哪一层?(下)
- 2024-04-26快刀斩乱麻,DevOps让代码评审也自动起来
- 2024-04-262024年最好用的10款ER图神器!
- 2024-04-2203-为啥大模型LLM还没能完全替代你?
- 2024-04-2101-大语言模型发展
- 2024-04-17基于SpringWeb MultipartFile文件上传、下载功能
- 2024-04-14个人开发者,Spring Boot 项目如何部署