How to make them the same size ```@Preview @Compos...
# compose
g
How to make them the same size
Copy code
@Preview
@Composable
fun Test() {
    Column(
        modifier = Modifier.fillMaxSize(),
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        ButtonText(
            text = "Super very large button"
            modifier = Modifier.wrapContentWidth(Alignment.CenterHorizontally)
        )
        ButtonText(
            text = "small"
            modifier = Modifier.wrapContentWidth(Alignment.CenterHorizontally)
        )
    }
}

@Composable
fun ButtonText(text: String, modifier: Modifier = Modifier) {
    Button(onClick = {}, modifier = modifier) {
        Text(text)
    }
}
a
wrap it in a Column, and set the modifier on it to
Modifier.wrapContentWidth(Alignment.CenterHorizontally)
, then button modifiers as fillMaxWidth()
g
Yeah, they are the same, but I meant to make small button as large as large one and not fill entire screen
d
Copy code
Column(fillMaxSize){
        Column(wrapContentWidth) {
          ButtonText(fillMaxSize)
          ButtonText(fillMaxSize)
        }
    }
?
g
@dmnk_89 Same result (
😞 2
a
@Mihai Popa
m
Copy code
Column(Modifier.preferredWidth(IntrinsicSize.Max)) {
    ButtonText(fillMaxSize)
    ButtonText(fillMaxSize)
}
g
Works! Finally. Thank you
z
1
👍 6
j
@Mihai Popa is it possible with a Row and buttons width?
m
@Javier not sure I follow the question, can you explain?
j
Having three buttons in a row where the maximum width a button can have is based on the button with more text
s
You can define a
Modifier.weight()
to the buttons, if each button has the same weight, they will have all the same size
1
j
Yes, I know I can do that but it is not the same result that I asked
m
Ah I see what you mean. Yes I think this will work as well:
Copy code
Row(Modifier.preferredWidth(IntrinsicSize.Max)) {
    Button1(weight(1f))
    Button2(weight(1f))
    Button3(weight(1f))
}
👍 1