Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

262
Views
How can I build the following layout in Compose?

I am wanting to build the following layout in Compose:

enter image description here

I have written the following code for this:

@Composable
fun MainScreenContent(){
    Surface(
        color = MaterialTheme.colors.primary,
        modifier = Modifier
            .wrapContentWidth(Alignment.CenterHorizontally)
            .wrapContentHeight(Alignment.CenterVertically)
    ) {
        Row() {
            Column(Modifier.weight(0.3F)) {
                Greeting("Android")
                Spacer(Modifier.padding(16.dp))
                Greeting("User")
            }
            Surface(modifier = Modifier.weight(0.4F),
                color = MaterialTheme.colors.primaryVariant,
            ){
                Spacer(Modifier.padding(16.dp))
            }

            Column(Modifier.weight(0.3F)) {
                Greeting("Android")
                Spacer(Modifier.padding(16.dp))
                Greeting("User")
            }
        }
    }

}

@Composable
fun Greeting(name: String) {
    Text(text = "Hello $name!",
        Modifier
            .padding(16.dp), fontSize = 30.sp)
}

But with this, I am getting the following output:

enter image description here

How can I achieve the objective?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Set the parent Surface's height to IntrinsicSize.Max, and add fillMaxHeight() to the inner Surface's modifier.

@Composable
fun MainScreenContent() {
    Surface(
        ...,
        modifier = Modifier
            .wrapContentWidth(Alignment.CenterHorizontally)
            .height(IntrinsicSize.Max),
    ) {
        Row {
            ...
            Surface(
                modifier = Modifier
                    .weight(0.4F)
                    .fillMaxHeight(),
                color = MaterialTheme.colors.primaryVariant,
            ) {
                Spacer(Modifier.padding(16.dp))
            }
            ...
        }
    }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!