java ui界面布局_鸿蒙 HarmonyOSJava UI之DependentLayout布局示例

0a53b5ff83c8f153f5fedc7f4b9f167d.png

DependentLayout简介

DependentLayout意为相对位置布局,与DirectionalLayout相比较有更多的排布方式,每个组件可以指定相对于其他同级组件的位置,也可以指定相对于父组件的位置。可以使用DependentLayout布局来实现更加复杂的UI界面,同时也可以和其他布局相结合组合出需要的UI界面。

常用属性

相对于指定组件的位置属性

263b03629739c33825026098cf5dcff2.png

xmlns:ohos="http://schemas.huawei.com/res/ohos"

ohos:height="match_parent"

ohos:width="match_parent"

ohos:alignment="center">

ohos:id="$+id:text_01"

ohos:height="match_content"

ohos:width="match_content"

ohos:background_element="$graphic:background_dependent_layout"

ohos:text="我是第一个Text."

ohos:text_size="50"

/>

ohos:id="$+id:text_02"

ohos:height="match_content"

ohos:width="match_content"

ohos:background_element="$graphic:background_dependent_layout"

ohos:text="我是第二个Text."

ohos:text_size="50"

ohos:above="$id:text_01"

/>

98974e043a52d913d0d7da364b2adba6.png

将ohos:above="$id:text_01" 改为ohos:below="$id:text_01",效果如下。

e365cd4eb822e84e2cdf91927d18a009.png

将ohos:above="$id:text_01" 改为ohos:left_of="$id:text_01",效果如下,其他自行验证。

ddbeb9ba6bfebf14447364df0ed0112a.png

子组件相对于父组件的位置属性

4c705aa68e51fb05273ce474e513eadf.png

xmlns:ohos="http://schemas.huawei.com/res/ohos"

ohos:height="match_parent"

ohos:width="match_parent"

ohos:alignment="center">

ohos:id="$+id:text_01"

ohos:height="match_content"

ohos:width="match_content"

ohos:background_element="$graphic:background_dependent_layout"

ohos:text="我是第一个Text."

ohos:text_size="50"

ohos:align_parent_bottom="true"

/>

ohos:id="$+id:text_02"

ohos:height="match_content"

ohos:width="match_content"

ohos:background_element="$graphic:background_dependent_layout"

ohos:text="我是第二个Text."

ohos:text_size="50"

ohos:align_parent_top="true"

/>

ohos:id="$+id:text_03"

ohos:height="match_content"

ohos:width="match_content"

ohos:background_element="$graphic:background_dependent_layout"

ohos:text="我是第三个Text."

ohos:text_size="50"

ohos:align_parent_right="true"

/>

ohos:id="$+id:text_04"

ohos:height="match_content"

ohos:width="match_content"

ohos:background_element="$graphic:background_dependent_layout"

ohos:text="我是第四个Text."

ohos:text_size="50"

ohos:center_in_parent="true"

/>

4c3bf3d9fb2696b23ca875a96c598067.png

示例

xmlns:ohos="http://schemas.huawei.com/res/ohos"

ohos:height="match_parent"

ohos:width="match_parent">

ohos:id="$+id:text_01"

ohos:height="70vp"

ohos:width="match_parent"

ohos:background_element="#CCCCCC"

ohos:text="Header"

ohos:text_alignment="center"

ohos:text_size="50"

ohos:align_parent_top="true"

/>

ohos:id="$+id:text_02"

ohos:height="match_parent"

ohos:width="100vp"

ohos:background_element="#5C6E71"

ohos:text="LEFT"

ohos:text_alignment="center"

ohos:text_size="50"

ohos:align_parent_left="true"

ohos:below="$id:text_01"

/>

ohos:id="$+id:text_03"

ohos:height="match_parent"

ohos:width="100vp"

ohos:background_element="#5C6E71"

ohos:text="Right"

ohos:text_alignment="center"

ohos:text_size="50"

ohos:align_parent_right="true"

ohos:below="$id:text_01"

/>

ohos:id="$+id:text_05"

ohos:height="match_parent"

ohos:width="match_parent"

ohos:background_element="#16CCB7"

ohos:text_alignment="center"

ohos:text="Center"

ohos:text_size="50"

ohos:right_margin="100vp"

ohos:below="$id:text_01"

ohos:right_of="$id:text_02"

/>

ohos:id="$+id:text_04"

ohos:height="50vp"

ohos:width="match_parent"

ohos:background_element="#CCCCCC"

ohos:text="Footer"

ohos:text_size="50"

ohos:align_parent_bottom="true"

/>

6d9b56d31b09bfccf2addb957e8b888e.png

至此,我们已经了解并会使用HarmonyOS Java UI的六大布局,下一节我们将对六大布局进行总结,并将前面没有提到的各类属性做详细的归纳。

【编辑推荐】

【责任编辑:jianghua TEL:(010)68476606】

点赞 0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值