Constrain layout custom view not updating size after layoutParams change

Viewed 72

I've seen similar questions but no answer has worked for me.

I'm trying to change my custom button width programmatically, but only the internal constrains change, not the container size inside my activity.

    private fun setSizeButton() {
        binding.container.layoutParams.width = context.dpToPx(NEW_SIZE)
        requestLayout()
        parent.requestLayout()
    }

For extra context, the container is just a constrainLayout with a TextView inside. What I'm I missing for this custom view to adapt to the new width?

Update: I change the custom view from a ConstrainLayout to LinearLayout and it worked, so what's preventing the ConstrainLayout from adapting to the new layout params?

0 Answers
Related