想了解更多内容,请访问:
专业成都网站建设公司,做排名好的好网站,排在同行前面,为您带来客户和效益!成都创新互联公司为您提供成都网站建设,五站合一网站设计制作,服务好的网站设计公司,网站设计、成都网站建设负责任的成都网站制作公司!
和华为官方合作共建的鸿蒙技术社区
https://harmonyos./#zz
DependentLayout简介
DependentLayout意为相对位置布局,与DirectionalLayout相比较有更多的排布方式,每个组件可以指定相对于其他同级组件的位置,也可以指定相对于父组件的位置。可以使用DependentLayout布局来实现更加复杂的UI界面,同时也可以和其他布局相结合组合出需要的UI界面。
常用属性
相对于指定组件的位置属性
- 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"
- />
将ohos:above="$id:text_01" 改为ohos:below="$id:text_01",效果如下。
将ohos:above="$id:text_01" 改为ohos:left_of="$id:text_01",效果如下,其他自行验证。
子组件相对于父组件的位置属性
- 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"
- />
示例
- 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"
- />
至此,我们已经了解并会使用HarmonyOS Java UI的六大布局,下一节我们将对六大布局进行总结,并将前面没有提到的各类属性做详细的归纳。
想了解更多内容,请访问:
和华为官方合作共建的鸿蒙技术社区
https://harmonyos./#zz
当前标题:鸿蒙HarmonyOSJavaUI之DependentLayout布局示例
网站路径:http://www.shufengxianlan.com/qtweb/news8/24758.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联