Home > front end >  How to set the width of a row to be equal to width of TextField in Jetpack Compose?
How to set the width of a row to be equal to width of TextField in Jetpack Compose?

Time:11-29

I want the width of the row that contains the button and the text to have the same width as the Text Fields. Here is what I have tried:

Column(
    modifier = Modifier.fillMaxSize().padding(padding),
    verticalArrangement = Arrangement.Center,
    horizontalAlignment = Alignment.CenterHorizontally
) {
    TextField(
        value = email,
        onValueChange = { email = it },
        placeholder = {Text(text = "Email")}
    )
    TextField(
        value = password,
        onValueChange = { password = it },
        placeholder = {Text(text = "Pass")}
    )
    Row {
        Button(
            onClick = {
                start(email, password)
            }
        ) {
            Text(
                text = "Start",
                fontSize = 18.sp
            )
        }
        Spacer(
            modifier = Modifier.weight(1f)
        )
        Text(
            text = "Skip"
        )
    }
}

This is what I get:

enter image description here

And this is what I expected:

enter image description here

Can I achieve that without setting fixed sizes?

CodePudding user response:

You can wrap the 3 composable with a Column and apply an enter image description here

  • Related