qimi
V2EX  ›  问与答

Android Studio 的可视化布局编辑器自动改变组件树的层次结构

  •  
  •   qimi · May 12, 2020 · 1495 views
    This topic created in 2219 days ago, the information mentioned may be changed or developed.

    在 Android studio 的可视化布局编辑器中,我原本的组件树结构为这样:

    ConstraintLayout1
    -   LinearLayout1
        -   Button1
        -   Button2
    -   ConstraintLayout2
    -   ConstraintLayout3
        -   Button3
    -   Button4
    

    当我修改 ConstraintLayout1 的 background 属性的时候,布局文件的层次结构会自动变为以下状态:

    ConstraintLayout1
    -   Button4
    -   LinearLayout1
        -   Button1
        -   Button2
    -   ConstraintLayout2
    -   ConstraintLayout3
        -   Button3
    

    Button变成了 ConstraintLayout1 下的第一个元素,请问这是什么原因导致的?

    我的 Android studio 的版本为 3.6.1 。

    1 replies    2020-05-13 10:20:29 +08:00
    chenjiajia9411
        1
    chenjiajia9411  
       May 13, 2020
    在约束布局里,写在后面的 view 会覆盖在前面的 view 上,你调整了前面 view 的属性并且没有做好约束之后就有可能出现这种问题。
    还有,约束布局做出来就是为了解决套娃问题的,所以不要在约束布局里面也套娃了,像你第一个两个 button 完全可以用 chain 来解决约束。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   994 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 82ms · UTC 22:02 · PVG 06:02 · LAX 15:02 · JFK 18:02
    ♥ Do have faith in what you're doing.