代码之家  ›  专栏  ›  技术社区  ›  Barry Fruitman

布局约束是否等效?

  •  0
  • Barry Fruitman  · 技术社区  · 6 年前

    我在努力理解 ConstraintSet .这两种方法会导致相同的布局约束吗?

    JAVA

    constraintSet.connect(textViewA.getId(), ConstraintSet.RIGHT, textViewB.getId(), ConstraintSet.LEFT);
    constraintSet.applyTo(constraintLayout);
    

    XML

    <TextView
        android:id="@+id/textViewA"
        app:layout_constraintRight_toLeftOf="@+id/textViewB"/>
    
    <TextView
        android:id="@id/textViewB"/>
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Cheticamp    6 年前

    假设 textViewA textViewB 参考文献是他们看起来参考的东西。在XML中 app:layout_constraintRight_toLeftOf="@+id/textViewB" 意思是“取此视图(textViewA)的右侧,并将其连接到textViewB的左侧。”Java代码的意思也是一样的。

    我建议您使用start/end,而不是left/right,如果您处于正确的API级别。 ConstraintLayout 在过去的代码和设计器中存在左/右问题,在我看来,开始/结束是首选。