首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >可以创建多个定向布局吗?

可以创建多个定向布局吗?
EN

Stack Overflow用户
提问于 2021-09-07 08:33:11
回答 2查看 76关注 0票数 0

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-09-09 01:47:29

您可以在资源布局的XML布局文件中为并行或嵌套创建多个DirectionalLayouts。

可以参考以下代码:

代码语言:javascript
运行
复制
<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>
票数 1
EN

Stack Overflow用户

发布于 2021-09-07 08:49:00

是的,我们可以在父DirectionalLayout示例使用中创建子DirectionalLayout

代码语言:javascript
运行
复制
<?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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69084864

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档