我在努力理解 ConstraintSet .这两种方法会导致相同的布局约束吗?
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"/>
假设 textViewA 和 textViewB 参考文献是他们看起来参考的东西。在XML中 app:layout_constraintRight_toLeftOf="@+id/textViewB" 意思是“取此视图(textViewA)的右侧,并将其连接到textViewB的左侧。”Java代码的意思也是一样的。
textViewA
textViewB
app:layout_constraintRight_toLeftOf="@+id/textViewB"
我建议您使用start/end,而不是left/right,如果您处于正确的API级别。 ConstraintLayout 在过去的代码和设计器中存在左/右问题,在我看来,开始/结束是首选。
ConstraintLayout