我有一个RecyclerView
列出项目。 RecyclerView
中的每个项目都是ConstraintLayout
的子类。我尝试使用ConstraintSet
中的onLayout
和onMeasure
甚至在子类(recyclerview中的每个单元格)的onDraw
函数中添加一些约束。该代码仅执行但未反映在视图中。
val redView = this.valueView.id
val parent = this.id
val greenView = this.diffView.id
val constraintSet = ConstraintSet()
constraintSet.clone(this)
constraintSet.connect(redView, ConstraintSet.LEFT, parent, ConstraintSet.LEFT, 30)
constraintSet.connect(redView, ConstraintSet.RIGHT, greenView, ConstraintSet.LEFT, 100)
constraintSet.connect(greenView, ConstraintSet.LEFT, redView, ConstraintSet.RIGHT, 20)
constraintSet.connect(greenView, ConstraintSet.RIGHT, parent, ConstraintSet.RIGHT)
constraintSet.applyTo(this)