可以创建多个方向布局吗?

Can multiple directional layouts be created?

使用 DevEco Studio 可以在另一个方向布局中创建一个方向布局吗? 如果是,我们该怎么做?

是的,我们可以在父 DirectionalLayout 中创建子 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>