Home > Net >  Divide one column for 2 rows in jetpack compose android
Divide one column for 2 rows in jetpack compose android

Time:02-03

enter image description here

I would like to divide one column with long text to 2 the same height and width row. It would be in case if text would be too long. Is It possible to divide one column with one Text for 2 rows in its half?

I couldn't make it, I have no idea.

CodePudding user response:

use weight

    Column() {
        Row(
            Modifier.weight(1f).background(Blue)
        ){
            Text(text = "Weight = 1", color = Color.White)
        }
        Row(
            Modifier.weight(1f).background(Yellow)
        ) {
            Text(text = "Weight = 1")
        }

}

CodePudding user response:

You can use a row and set modifier weight: 1f:

Row {
        TextField(
            value = "Test Test Test Test Test Test Test Test Test Test Test Test"  
                    " Test Test Test Test Test Test Test Test ",
            onValueChange = {},
            modifier = Modifier.weight(1f)
        )
        TextField(
            value = "Test Test Test Test Test Test TesTest Test Test Test "  
                    "Test Test Test Test Test Test Test Test Test ",
            onValueChange = {},
            modifier = Modifier.weight(1f)
        )
    }

and if you want to have the second TextField in the next line if it's breaking line, you can use FlowRow

https://google.github.io/accompanist/flowlayout

  • Related