```class SomeWidget : ConstraintLayout { cons...
# android
u
Copy code
class SomeWidget : ConstraintLayout {

    constructor(
        context: Context
    ) : this(context, null) {

    }

    constructor(
        context: Context,
        attrs: AttributeSet?
    ) : this(context, attrs, 0) {

    }

    constructor(
        context: Context,
        attrs: AttributeSet?,
        defStyleAttr: Int
    ) : super(context, attrs, defStyleAttr) {
        inflate()
    }

    fun addSubviews() {
        val views = mutableListOf<View>()
        repeat(2) { count ->
            views.add(
                TextView(context).apply {
                    text = "Test $count"
                    setBackgroundResource(R.drawable.rectangle_debug)
                }
            )
        }
        views.forEach {
            addView(it)
        }

        flow.apply {
            //setWrapMode(Flow.WRAP_CHAIN)
        }

        flow.referencedIds = views.map { it.id }.toIntArray()

        post { requestLayout() }
    }

    private fun inflate() {
        LayoutInflater.from(context).inflate(R.layout.widget_featured_relation, this)
    }
}
Copy code
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="<http://schemas.android.com/apk/res/android>"
    xmlns:app="<http://schemas.android.com/apk/res-auto>">

    <androidx.constraintlayout.helper.widget.Flow
        android:id="@+id/flow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</merge>
I am totally missing something. Could someone explain to me why this custom view is rendered this way:
😶 2
🧵 3
e
id isn't auto populated, you need to specify or create ids yourself.
👍 1
also not a Kotlin issue.