在ConstraintLayout的onLayout中添加约束在RecyclerView中不起作用

时间:2018-10-20 12:11:38

标签: android android-recyclerview android-constraintlayout android-viewholder

我有一个RecyclerView列出项目。 RecyclerView中的每个项目都是ConstraintLayout的子类。我尝试使用ConstraintSet中的onLayoutonMeasure甚至在子类(recyclerview中的每个单元格)的onDraw函数中添加一些约束。该代码仅执行但未反映在视图中。

Here is the output of my code

    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)

0 个答案:

没有答案