使用 DevEco Studio 可以在另一个方向布局中创建一个方向布局吗?如果是,我们该怎么做?
问问题
68 次
2 回答
2
是的,我们可以在父DirectionalLayout中创建 Child 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:orientation="vertical"
ohos:alignment="center"
ohos:total_weight="4">
<DirectionalLayout
ohos:weight="1"
ohos:id="$+id:firstChild"
ohos:height="0vp"
ohos:width="match_parent"
ohos:orientation="horizontal"
ohos:margin="5vp"
ohos:total_weight="3"
ohos:background_element="$color:material_light_brown">
<DependentLayout
ohos:weight="1"
ohos:height="match_parent"
ohos:width="0vp"
ohos:margin="5vp"
ohos:background_element="$color:material_brown"/>
<DependentLayout
ohos:weight="1"
ohos:height="match_parent"
ohos:width="0vp"
ohos:margin="5vp"
ohos:background_element="$color:material_brown"/>
<DependentLayout
ohos:weight="1"
ohos:height="match_parent"
ohos:width="0vp"
ohos:margin="5vp"
ohos:background_element="$color:material_brown"/>
</DirectionalLayout>
<DependentLayout
ohos:weight="1"
ohos:height="0vp"
ohos:width="match_parent"
ohos:margin="5vp"
ohos:background_element="$color:material_brown"/>
<DependentLayout
ohos:weight="1"
ohos:height="0vp"
ohos:width="match_parent"
ohos:margin="5vp"
ohos:background_element="$color:material_brown"/>
<DependentLayout
ohos:weight="1"
ohos:height="0vp"
ohos:width="match_parent"
ohos:margin="5vp"
ohos:background_element="$color:material_brown"/>
</DirectionalLayout>
于 2021-09-07T08:49:00.200 回答
1
您可以在资源布局的 XML 布局文件中创建多个 DirectionalLayout,用于并行或嵌套。
可以参考以下代码:
<DirectionalLayout
ohos:height="match_content"
ohos:width="match_parent"
ohos:orientation="horizontal">
<DirectionalLayout
ohos:height="match_content"
ohos:width="match_parent"
ohos:orientation="horizontal">
</DirectionalLayout>
<DirectionalLayout
ohos:height="match_content"
ohos:width="match_parent"
ohos:orientation="horizontal">
</DirectionalLayout>
</DirectionalLayout>
于 2021-09-09T01:47:29.210 回答