约束布局中你在我左边,我在你右边,为何程序中断呢?

在约束布局(DependentLayout)中,Text One在Text Two左边,Text Two 在Text one右边,为何程序运行中断?

<?xml version="1.0" encoding="utf-8"?>
<DependentLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:alignment="horizontal_center">
    <Text
        ohos:id="$+id:txtOne"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:text="Text One"
        ohos:text_alignment="center"
        ohos:background_element="#CCFFE7"
        ohos:text_size="20fp"
        ohos:align_parent_bottom="true"
        ohos:align_parent_left="true"
        ohos:left_of="$id:txtTwo"/>
    <Text
        ohos:id="$+id:txtTwo"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:text="Text Two"
        ohos:text_alignment="center"
        ohos:background_element="#FF8F95"
        ohos:text_size="20fp"
        ohos:align_parent_bottom="true"
        ohos:right_of="$id:txtOne"/>
</DependentLayout>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
DependentLayout
2020-11-18 14:52:08
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
小囧宝宝

ohos:left_of="$id:txtTwo"第一个text中的这一行去掉就可以,第二个text中指定相对第一个text的位置,不用相互指定

分享
微博
QQ
微信
回复2
2020-11-19 19:09:14


相关问题
HarmonyOS ArkUI是否有约束布局
829浏览 • 1回复 待解决
想用XML布局增加一个图片怎么实现?
11757浏览 • 4回复 待解决
HarmonyOS 布局超出边界,无法约束
626浏览 • 1回复 待解决