Anyone know how to make compose where you have 2 d...
# compose
d
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
Looks like you want
weight(1f, fill = false)
d
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
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
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
Very interesting. I just verified yeah all works the same. Appreciate the clarification that weights are the way to go.
o
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
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