【问题标题】:Can multiple directional layouts be created?可以创建多个方向布局吗?
【发布时间】:2021-09-07 08:33:11
【问题描述】:

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

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: java android huawei-mobile-services harmonyos deveco-studio


【解决方案1】:

是的,我们可以在父 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>

【讨论】:

    【解决方案2】:

    您可以在资源布局的 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-13
      相关资源
      最近更新 更多