https://kotlinlang.org logo
#compose
Title
# compose
d

David Corrado

07/22/2022, 4:58 PM
Anyone know how to make compose where you have 2 different texts with large text work more like if you did it with the layout system or at least where the second text does not disappear. 🧵
In the layout legacy system it seems from testing with a constraintlayout it would make it so the 2 texts take 50% if they are both large. If the 2nd text is small it will just wrap and the 1st text will expand to take the extra space. Like is there a way to make compose work similar or at minimum not hide the second text?
Heres the compose example for reference
Copy code
Row(modifier = Modifier.fillMaxWidth()) {
    Text(text = "Test3 Test3 Test3 Test3 Test3 Test3 Test3 Test3 Test3 Test3 Test3 Test3 Test3 ")
    Text(
        "Blah blah blah",
        modifier = Modifier
    )
}
I can manually do weights. But is there a means to make it automatic
Or if there are any blogs on this I would love to read through it if you find any. Not finding much by googling
f

Francesc

07/22/2022, 5:06 PM
Looks like you want
weight(1f, fill = false)
d

David Corrado

07/22/2022, 5:08 PM
Yeah the problem with that is that it always will do 50/50 and not wrap the content of the text of the shorter one
Of course I could do different weights but I want it to be more of automatic. Do 50/50 unless there is something shorter then wrap that and use the available space
f

Francesc

07/22/2022, 5:10 PM
you would do the weight only on one of the texts, the long one. Otherwise, if you have both text potentially being long, you may need to measure them and adjust the sizes after they've been measured. This could also be an option for a
Layout
(the equivalent to a
ViewGroup
)
👆 1
🙏 1
r

romainguy

07/22/2022, 5:12 PM
There was nothing “automatic” about this in the View system. If you used ConstraintLayout with Views and want to replicate that behavior, you should try Compose’s ConstraintLayout.
Otherwise Francesc’s solution of setting a weight on only one of the text widgets is correct, and how it would be done in
LinearLayout
with Views
🙏 1
d

David Corrado

07/22/2022, 5:26 PM
Very interesting. I just verified yeah all works the same. Appreciate the clarification that weights are the way to go.
o

Oleksandr Balan

07/22/2022, 7:57 PM
Maybe it's worth to check this Layout implementation: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1648551227037639?thread_ts=1648467352.438719&cid=CJLTWPH7S Isn't it what you want to achieve?
s

Stylianos Gakis

07/22/2022, 10:49 PM
I was gonna link to that discussion as well. And if you want something to copy-paste to test asap give this a try. We've been using this for quite some time now in production and I'm super happy with how it turned out.
👍 1
3 Views