【鸿蒙】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组件学习五之面试宝典的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程