I have a constraint layout with a simple card view with a text inside, and a text at the bottom. I want the card's width to be at least the width of the bottom text. So something like setting a minimum width.
I drew a picture illustrating what I want but wasn't able to implement it in Constraint Layout.
Barriers will do the magic for you!
With this feature you automatically get the width of the widest object in a certain scope.
From Android Documentaion:
A Barrier references multiple widgets as input, and creates a virtual guideline based on the most extreme widget on the specified side. For example, a left barrier will align to the left of all the referenced views.
The following xml will check the widest width of the views content_text
and bottom_text
Now you can use this barrier as a constrain in any other view (inside the same ConstraintLayout)
That's what my result looks like:
Sample 1
Sample 2
My complete XML:
Hope this helps.
Here could you read more about barriers