我想以编程方式向 ConstraintLayout
内的 TextView
添加一些约束。我知道我必须使用 ConstraintSet
,但我不知道如何在 textView
上添加 xml 属性:layout_constraintRight_toLeftOf
(及其等效项) > 在 Android 中的 Java 中。
感谢任何帮助!!
最佳答案
可以这样设置,
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(layout); // root layout
// If you want to align parent to the layout left
constraintSet.connect(textView.getId(), ConstraintSet.LEFT, layout.getId(), ConstraintSet.LEFT);
// If you want to align to the left of one more textview - second text view
constraintSet.connect(textView.getId(), ConstraintSet.RIGHT, textView1.getId(), ConstraintSet.LEFT);
/*______________________________
| Text1 Text2 |
| |*/
constraintSet.applyTo(layout);
关于java - 在android中以编程方式相当于layout_constraintRight_toLeftOf的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45848269/