布局约束是否等效?
Are the layout constraints equivalent?
我正在努力理解 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"
表示"take the right side of this view (textViewA) and attach it to the left side of textViewB." Java代码中的意思相同。
如果你的 API 级别合适,我建议你使用 start/end 而不是 left/right。 ConstraintLayout
在过去的代码和设计器中与 left/right 有一些问题,IMO,start/end 是首选。
我正在努力理解 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"
表示"take the right side of this view (textViewA) and attach it to the left side of textViewB." Java代码中的意思相同。
如果你的 API 级别合适,我建议你使用 start/end 而不是 left/right。 ConstraintLayout
在过去的代码和设计器中与 left/right 有一些问题,IMO,start/end 是首选。