【HarmonyOS】【xml】初学XML布局作业

简介: 【HarmonyOS】【xml】初学XML布局作业

页面案例1


q6.png

q5.png

代码如下:

<?xml version="1.0" encoding="utf-8"?>
<!--依赖布局-->
<DependentLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:background_element="#CCCCCC"
    >
<!--添加ListContainer标识多行数据    -->
        <ListContainer
            ohos:id="$+id:list_container"
            ohos:height="match_content"
            ohos:width="match_parent"
            ohos:above="$id:layout_bottom"
            >
        </ListContainer>
<!--按钮子布局-->
        <DirectionalLayout
            ohos:id="$+id:layout_bottom"
            ohos:height="match_content"
            ohos:width="match_parent"
            ohos:orientation="horizontal"
            ohos:align_parent_bottom="true"
            >
<!--            编辑城市按钮-->
            <Button
                ohos:id="$+id:button_edit"
                ohos:height="match_content"
                ohos:width="match_parent"
                ohos:text="编辑城市"
                ohos:background_element="#1F69FF"
                ohos:text_color="#FFFFFF"
                ohos:text_size="24vp"
                ohos:weight="1"
                ohos:layout_alignment="bottom"
                />
<!--            添加城市按钮-->
            <Button
                ohos:id="$+id:button_add"
                ohos:height="match_content"
                ohos:width="match_parent"
                ohos:text="添加城市"
                ohos:background_element="#FFFFFF"
                ohos:text_color="#1F69FF"
                ohos:text_size="24vp"
                ohos:weight="1"
                ohos:layout_alignment="bottom"
                />
    </DirectionalLayout>
</DependentLayout>
<?xml version="1.0" encoding="utf-8"?>
<!--依赖布局-->
<DependentLayout      //依赖布局
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:background_element="#CCCCCC"
    >
<!--添加ListContainer标识多行数据    -->
        <ListContainer
            ohos:id="$+id:list_container"
            ohos:height="match_content"
            ohos:width="match_parent"
            ohos:above="$id:layout_bottom"   //让此组件下边缘与另一个组件的上边缘对齐
            >
        </ListContainer>
<!--按钮子布局-->
        <DirectionalLayout
            ohos:id="$+id:layout_bottom"
            ohos:height="match_content"
            ohos:width="match_parent"
            ohos:orientation="horizontal"
            ohos:align_parent_bottom="true"   //将底边与父组件对齐
            >
<!--            编辑城市按钮-->
            <Button
                ohos:id="$+id:button_edit"
                ohos:height="match_content"
                ohos:width="match_parent"
                ohos:text="编辑城市"
                ohos:background_element="#1F69FF"
                ohos:text_color="#FFFFFF"
                ohos:text_size="24vp"
                ohos:weight="1" //权重:1
                ohos:layout_alignment="bottom"    //对齐方式:底部对齐
                />
<!--            添加城市按钮-->
            <Button
                ohos:id="$+id:button_add"
                ohos:height="match_content"
                ohos:width="match_parent"
                ohos:text="添加城市"
                ohos:background_element="#FFFFFF"
                ohos:text_color="#1F69FF"
                ohos:text_size="24vp"
                ohos:weight="1" //权重:1
                ohos:layout_alignment="bottom" //对齐方式:底部对齐
                />
    </DirectionalLayout>
</DependentLayout>

页面案例2


q4.png

q3.png

<?xml version="1.0" encoding="utf-8"?>
<DependentLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:background_element="#F5FFC3"
    ohos:orientation="vertical"
    >
<!--    线性布局 Picker-->
<DirectionalLayout
        ohos:height="match_parent"
        ohos:width="match_parent"
        ohos:orientation="horizontal"
        ohos:background_element="#FFAFF8CE"
        ohos:above="$id:layout_bottom"
        >
        <Picker
            ohos:id="$+id:picker_province"
            ohos:height="match_parent"
            ohos:width="match_parent"
            ohos:weight="1"
            ohos:normal_text_size="28vp"
            ohos:selected_text_size="48vp"
            ohos:normal_text_color="#FF6D6D6D"
            ohos:selected_text_color="#FF000000"
            ohos:top_line_element="#000000"
            ohos:bottom_line_element="#000000"
            ohos:layout_alignment="horizontal_center"
            />
        <Picker
            ohos:id="$+id:picker_city"
            ohos:height="match_parent"
            ohos:width="match_parent"
            ohos:weight="1"
            ohos:normal_text_size="28vp"
            ohos:selected_text_size="48vp"
            ohos:normal_text_color="#FF6D6D6D"
            ohos:selected_text_color="#FF000000"
            ohos:top_line_element="#000000"
            ohos:bottom_line_element="#000000"
            ohos:layout_alignment="horizontal_center"
            />
        <Picker
            ohos:id="$+id:picker_county"
            ohos:height="match_parent"
            ohos:width="match_parent"
            ohos:weight="1"
            ohos:normal_text_size="28vp"
            ohos:selected_text_size="48vp"
            ohos:normal_text_color="#FF6D6D6D"
            ohos:selected_text_color="#FF000000"
            ohos:top_line_element="#000000"
            ohos:bottom_line_element="#000000"
            ohos:layout_alignment="horizontal_center"
            />
    </DirectionalLayout>
<!--    线性布局 按钮-->
    <DirectionalLayout
        ohos:id="$+id:layout_bottom"
        ohos:height="match_content"
        ohos:width="match_parent"
        ohos:orientation="horizontal"
        ohos:align_parent_bottom="true"
        >
        <!--            取消按钮-->
        <Button
            ohos:id="$+id:button_cancel"
            ohos:height="match_content"
            ohos:width="match_parent"
            ohos:text="取消"
            ohos:background_element="#FFFFFF"
            ohos:text_color="#1F69FF"
            ohos:text_size="18vp"
            ohos:weight="1"
            ohos:layout_alignment="bottom"
            ohos:padding="5vp"
            />
        <!--            确定按钮-->
        <Button
            ohos:id="$+id:button_enter"
            ohos:height="match_content"
            ohos:width="match_parent"
            ohos:text="确定"
            ohos:background_element="#1F69FF"
            ohos:text_color="#FFFFFF"
            ohos:text_size="18vp"
            ohos:weight="1"
            ohos:layout_alignment="bottom"
            ohos:padding="5vp"
            />
    </DirectionalLayout>
    </DependentLayout>
<?xml version="1.0" encoding="utf-8"?>
<DependentLayout  //依赖布局
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:background_element="#F5FFC3"
    ohos:orientation="vertical"   //子布局上下排列
    >
<!--    线性布局 Picker-->
<DirectionalLayout
        ohos:height="match_parent"
        ohos:width="match_parent"
        ohos:orientation="horizontal"  //子布局左右排列
        ohos:background_element="#FFAFF8CE"
        ohos:above="$id:layout_bottom"
        >
        <Picker
            ohos:id="$+id:picker_province"
            ohos:height="match_parent"
            ohos:width="match_parent"
            ohos:weight="1"
            ohos:normal_text_size="28vp"
            ohos:selected_text_size="48vp"
            ohos:normal_text_color="#FF6D6D6D"
            ohos:selected_text_color="#FF000000"
            ohos:top_line_element="#000000"              //顶部框线:颜色值
            ohos:bottom_line_element="#000000"           //底部框线:颜色值
            ohos:layout_alignment="horizontal_center"   //对齐方式:居中对齐
            />
        <Picker
            ohos:id="$+id:picker_city"
            ohos:height="match_parent"
            ohos:width="match_parent"
            ohos:weight="1"
            ohos:normal_text_size="28vp"
            ohos:selected_text_size="48vp"
            ohos:normal_text_color="#FF6D6D6D"
            ohos:selected_text_color="#FF000000"
            ohos:top_line_element="#000000"
            ohos:bottom_line_element="#000000"
            ohos:layout_alignment="horizontal_center"
            />
        <Picker
            ohos:id="$+id:picker_county"
            ohos:height="match_parent"
            ohos:width="match_parent"
            ohos:weight="1"
            ohos:normal_text_size="28vp"
            ohos:selected_text_size="48vp"
            ohos:normal_text_color="#FF6D6D6D"
            ohos:selected_text_color="#FF000000"
            ohos:top_line_element="#000000"
            ohos:bottom_line_element="#000000"
            ohos:layout_alignment="horizontal_center"
            />
    </DirectionalLayout>
<!--    线性布局 按钮-->
    <DirectionalLayout
        ohos:id="$+id:layout_bottom"
        ohos:height="match_content"
        ohos:width="match_parent"
        ohos:orientation="horizontal"
        ohos:align_parent_bottom="true"     //此组件底线与父组件底线对齐
        >
        <!--            取消按钮-->
        <Button
            ohos:id="$+id:button_cancel"
            ohos:height="match_content"
            ohos:width="match_parent"
            ohos:text="取消"
            ohos:background_element="#FFFFFF"
            ohos:text_color="#1F69FF"
            ohos:text_size="18vp"
            ohos:weight="1"
            ohos:layout_alignment="bottom"
            ohos:padding="5vp"
            />
        <!--            确定按钮-->
        <Button
            ohos:id="$+id:button_enter"
            ohos:height="match_content"
            ohos:width="match_parent"
            ohos:text="确定"
            ohos:background_element="#1F69FF"
            ohos:text_color="#FFFFFF"
            ohos:text_size="18vp"
            ohos:weight="1"
            ohos:layout_alignment="bottom"
            ohos:padding="5vp"
            />
    </DirectionalLayout>
    </DependentLayout>

页面案例3


q2.png

q1.png

<?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:alignment="center"
    ohos:orientation="vertical">
<Text
    ohos:height="match_content"
    ohos:width="match_content"
    ohos:text_size="18vp"
    ohos:top_margin="20vp"
    ohos:text="地区"
    />
    <Text
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:text_size="18vp"
        ohos:top_margin="20vp"
        ohos:text="温度"
        />
    <Text
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:text_size="18vp"
        ohos:top_margin="20vp"
        ohos:text="天气"
        />
</DirectionalLayout>
<?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:alignment="center"
    ohos:orientation="vertical">  //上下布局
<Text
    ohos:height="match_content"
    ohos:width="match_content"
    ohos:text_size="18vp"
    ohos:top_margin="20vp"  //顶部边距
    ohos:text="地区"
    />
    <Text
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:text_size="18vp"
        ohos:top_margin="20vp"
        ohos:text="温度"
        />
    <Text
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:text_size="18vp"
        ohos:top_margin="20vp"
        ohos:text="天气"
        />
</DirectionalLayout>
相关文章
|
容器
50.[HarmonyOS NEXT RelativeContainer案例七] 均匀分布的底部导航栏:水平链布局技术详解
底部导航栏是移动应用中最常见的导航元素之一,它通常包含多个均匀分布的图标或按钮,用于在应用的主要功能之间切换。在HarmonyOS NEXT中,RelativeContainer组件提供了强大的链式布局(Chain)功能,能够轻松实现元素的均匀分布,非常适合底部导航栏的实现。本教程将详细讲解如何利用RelativeContainer的水平链布局功能实现一个美观、均匀分布的底部导航栏。
426 72
|
容器
49.[HarmonyOS NEXT RelativeContainer案例六] 智能屏障布局:打造自适应聊天气泡界面
在现代移动应用开发中,聊天界面是最常见的交互场景之一。一个优秀的聊天界面需要能够适应不同长度的消息内容,保持布局的一致性和美观性。HarmonyOS NEXT的RelativeContainer组件提供了强大的屏障(Barrier)功能,能够根据内容动态调整布局,非常适合实现聊天气泡这类需要自适应内容边界的UI元素。本教程将详细讲解如何利用RelativeContainer的屏障功能实现一个自适应的聊天气泡界面。
368 70
|
编解码 UED 开发者
【HarmonyOS Next之旅】基于ArkTS开发(二) -> UI开发之常见布局
本文主要介绍了自适应布局与响应式布局的相关内容。自适应布局部分涵盖线性布局、层叠布局、弹性布局和网格布局,详细说明了各布局的特性及使用方法,例如线性布局中的排列、拉伸与缩放,弹性布局的方向、换行与对齐方式等。响应式布局则重点讲解了栅格系统和媒体查询,阐述如何通过栅格组件和媒体查询条件实现不同设备上的适配效果。这些技术帮助开发者灵活应对多尺寸屏幕的设计需求,提升用户体验。
801 55
|
开发者 容器
52.[HarmonyOS NEXT RelativeContainer案例九] 灵活比例布局:链中节点权重分配技术详解
在现代UI设计中,按照特定比例分配空间的布局需求非常常见,例如黄金分割比例的内容区域、按照特定比例分配的多列布局等。HarmonyOS NEXT的RelativeContainer组件提供了链中节点权重(chainWeight)功能,能够按照指定的权重比例分配链中组件的空间,实现灵活的比例布局。本教程将详细讲解如何利用RelativeContainer的链中节点权重功能实现灵活的比例布局,帮助你掌握这一强大的布局技术。
414 50
|
UED 开发者 容器
51.[HarmonyOS NEXT RelativeContainer案例八] 精确控制的搜索栏:链中偏移布局技术详解
搜索栏是现代应用中常见的UI组件,通常包含一个搜索图标和一个输入框。在设计搜索栏时,我们常常需要精确控制组件之间的位置关系,使其既美观又符合用户的使用习惯。HarmonyOS NEXT的RelativeContainer组件提供了链中偏移(bias)功能,能够精确控制链中组件的位置,非常适合实现搜索栏这类需要精确定位的UI元素。本教程将详细讲解如何利用RelativeContainer的链中偏移功能实现一个美观、实用的搜索栏。
345 23
|
定位技术 容器
48.[HarmonyOS NEXT RelativeContainer案例五] 精确表单布局:辅助线定位技术打造专业级UI
在HarmonyOS NEXT的UI开发中,表单是常见且重要的界面元素。创建对齐精确、布局合理的表单需要精细的定位控制。RelativeContainer提供的辅助线(Guideline)功能,为表单布局提供了强大的支持。本教程将详细讲解如何使用RelativeContainer的辅助线功能实现精确的表单布局,帮助你掌握这一专业级UI技术。
421 7
|
定位技术 UED
70. [HarmonyOS NEXT 实战案例九] 旅游景点网格布局(下)
在上一篇教程中,我们学习了如何使用GridRow和GridCol组件实现基本的旅游景点网格布局。本篇教程将在此基础上,深入探讨如何优化布局、添加交互功能,以及实现更多高级特性,打造一个功能完善的旅游景点应用。
287 1
|
容器
69.[HarmonyOS NEXT 实战案例九] 旅游景点网格布局(上)
本教程将详细讲解如何使用HarmonyOS NEXT中的GridRow和GridCol组件实现旅游景点网格布局。通过网格布局,我们可以以美观、规整的方式展示各种旅游景点信息,为用户提供良好的浏览体验。
270 1
|
UED
68.[HarmonyOS NEXT 实战案例八] 电影票务网格布局(下)
在上一篇教程中,我们学习了如何使用GridRow和GridCol组件实现基本的电影票务网格布局。本篇教程将在此基础上,深入探讨如何优化布局、添加交互功能,以及实现更多高级特性,打造一个功能完善的电影票务应用。
302 1
|
开发者 容器
67.[HarmonyOS NEXT 实战案例八] 电影票务网格布局(上)
在移动应用开发中,电影票务应用是一个常见的场景,用户可以通过应用查看正在热映的电影信息,并进行选座购票等操作。本教程将详细讲解如何使用HarmonyOS NEXT的GridRow和GridCol组件实现电影票务应用中的电影列表网格布局,帮助开发者掌握网格布局的基本用法和实现技巧。
295 1

热门文章

最新文章

相关课程

更多