【发布时间】:2021-09-07 08:33:11
【问题描述】:
使用 DevEco Studio 可以在另一种方向布局中创建一个方向布局吗? 如果是,我们该怎么做?
【问题讨论】:
-
请提供足够的代码,以便其他人更好地理解或重现问题。
标签: java android huawei-mobile-services harmonyos deveco-studio
使用 DevEco Studio 可以在另一种方向布局中创建一个方向布局吗? 如果是,我们该怎么做?
【问题讨论】:
标签: java android huawei-mobile-services harmonyos deveco-studio
是的,我们可以在父 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>
【讨论】:
您可以在资源布局的 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>
【讨论】: