java - 在android中以编程方式相当于layout_constraintRight_toLeftOf的是什么?

标签 java android android-constraintlayout

我想以编程方式向 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/

相关文章:

java - Google libphone 号码,用于获取相同国家代码的国家名称

android - 如何更改 RatingBar 的星图?

java - Primefaces ajax字符集问题

java - 原子引用用法

android - 如何在 Android 的 ContextMenu 中添加按钮

android - 约束布局垂直对齐中心

Android - 对新添加的 ImageView 和 TextView 设置约束

android - ConstraintLayout中的动态circleRadius

java - 匹配以某个路径元素开头的任何 url

android - 关闭应用程序时播放背景音乐