Bird
Raised Fist0
Android Kotlinmobile~20 mins

Column and Row layouts in Android Kotlin - Mini App: Build & Ship

Choose your learning style10 modes available
Build: ColumnRowLayoutScreen
This screen shows a simple layout using Column and Row to arrange text and buttons vertically and horizontally.
Target UI
-------------------------
|       ColumnRowLayout  |
|-----------------------|
| Text 1                |
| Text 2                |
|-----------------------|
| [Button 1] [Button 2] |
|-----------------------|
Use a Column to arrange two TextViews vertically at the top.
Below the texts, use a Row to arrange two Buttons horizontally with some spacing.
Center the whole layout vertically and horizontally on the screen.
Add padding around the content.
Starter Code
Android Kotlin
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

class ColumnRowLayoutScreen : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            // TODO: Add your layout here
        }
    }
}
Task 1
Task 2
Task 3
Solution
Android Kotlin
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

class ColumnRowLayoutScreen : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Column(
                modifier = Modifier
                    .fillMaxSize()
                    .padding(16.dp),
                verticalArrangement = Arrangement.Center,
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                Text(text = "Text 1")
                Spacer(modifier = Modifier.height(8.dp))
                Text(text = "Text 2")
                Spacer(modifier = Modifier.height(24.dp))
                Row(
                    horizontalArrangement = Arrangement.spacedBy(16.dp),
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Button(onClick = {}) {
                        Text(text = "Button 1")
                    }
                    Button(onClick = {}) {
                        Text(text = "Button 2")
                    }
                }
            }
        }
    }
}

We use a Column to stack two Text elements vertically. We center the whole column in the screen using fillMaxSize() with verticalArrangement = Arrangement.Center and horizontalAlignment = Alignment.CenterHorizontally. Padding adds space around the content.

Between the texts and buttons, Spacer adds vertical space.

The Row arranges two buttons horizontally with space between them using horizontalArrangement = Arrangement.spacedBy(16.dp). Buttons have empty click handlers for now.

Final Result
Completed Screen
-------------------------
|       ColumnRowLayout  |
|-----------------------|
|        Text 1         |
|        Text 2         |
|                       |
|  [Button 1] [Button 2]|
|-----------------------|
Buttons can be tapped but do nothing currently.
Stretch Goal
Add a third button below the row that spans the full width with label 'Button 3'.
💡 Hint
Add another Button inside the Column below the Row with Modifier.fillMaxWidth() and some top padding.

Practice

(1/5)
1. Which layout arranges its child views vertically in Android Kotlin?
easy
A. Row
B. Column
C. Grid
D. FrameLayout

Solution

  1. Step 1: Understand layout orientation

    Column arranges children vertically, stacking them top to bottom.
  2. Step 2: Compare with other layouts

    Row arranges children horizontally, Grid arranges in a grid, FrameLayout stacks overlapping.
  3. Final Answer:

    Column -> Option B
  4. Quick Check:

    Vertical arrangement = Column [OK]
Hint: Vertical means top to bottom, so use Column [OK]
Common Mistakes:
  • Confusing Row with Column
  • Thinking Grid arranges vertically only
  • Mixing FrameLayout stacking with vertical layout
2. Which of the following is the correct Kotlin syntax to create a Row layout with two Text views inside?
easy
A. Row( Text("Hello"), Text("World") )
B. Column { Text("Hello") Text("World") }
C. Row { Text("Hello") Text("World") }
D. Row { TextView("Hello") TextView("World") }

Solution

  1. Step 1: Identify correct Row syntax

    Row uses curly braces with child composables inside, separated by lines.
  2. Step 2: Check child components

    Text is the correct composable for text display, TextView is Android View, not Compose.
  3. Final Answer:

    Row { Text("Hello") Text("World") } -> Option C
  4. Quick Check:

    Row uses braces and Text composables [OK]
Hint: Use braces {} for layouts and Text composable for text [OK]
Common Mistakes:
  • Using parentheses instead of braces for Row
  • Using Column instead of Row
  • Using TextView instead of Text composable
3. What will be the visual arrangement of the following code?
Column {
  Text("A")
  Row {
    Text("B")
    Text("C")
  }
  Text("D")
}
medium
A. A at top, B and C side by side in middle, D at bottom vertically
B. A, B, C, D all side by side horizontally
C. A, B, C stacked vertically, D missing
D. Only A and D visible, B and C hidden

Solution

  1. Step 1: Analyze outer Column layout

    Column stacks children vertically: Text("A"), then Row, then Text("D").
  2. Step 2: Analyze inner Row layout

    Row arranges Text("B") and Text("C") horizontally side by side.
  3. Final Answer:

    A at top, B and C side by side in middle, D at bottom vertically -> Option A
  4. Quick Check:

    Column vertical + Row horizontal = mixed layout [OK]
Hint: Column stacks vertically, Row stacks horizontally inside [OK]
Common Mistakes:
  • Thinking Row inside Column stacks vertically
  • Ignoring inner Row layout
  • Assuming all texts are horizontal
4. Identify the error in this Kotlin Compose code snippet:
Row {
  Text("Hello")
  Text("World")
  Column(
    Text("Nested")
  )
}
medium
A. Missing comma between Text("Hello") and Text("World")
B. Text composable cannot be inside Column
C. Row cannot contain Column as child
D. Column should use braces {} instead of parentheses ()

Solution

  1. Step 1: Check Column syntax

    Column uses curly braces {} to enclose children, not parentheses ().
  2. Step 2: Verify child composables

    Text can be inside Column; Row can contain Column; commas are not needed between children.
  3. Final Answer:

    Column should use braces {} instead of parentheses () -> Option D
  4. Quick Check:

    Layouts use braces {} for children [OK]
Hint: Use {} for layout children, not () [OK]
Common Mistakes:
  • Using () instead of {} for layouts
  • Thinking commas are required between children
  • Believing nested layouts are not allowed
5. You want to create a UI where three buttons are arranged horizontally, but the middle button should be twice as wide as the others. Which layout and modifier approach is best in Kotlin Compose?
hard
A. Use Row with weights: Button1 weight=1, Button2 weight=2, Button3 weight=1
B. Use Column with padding on middle button
C. Use Row with fixed width buttons and margin on middle button
D. Use Column with weight modifiers on buttons

Solution

  1. Step 1: Choose horizontal layout

    Row arranges children horizontally, perfect for side-by-side buttons.
  2. Step 2: Use weight modifier for sizing

    Assign weights to buttons to control relative widths; middle button weight=2 makes it twice as wide.
  3. Final Answer:

    Use Row with weights: Button1 weight=1, Button2 weight=2, Button3 weight=1 -> Option A
  4. Quick Check:

    Row + weights control horizontal size [OK]
Hint: Use Row and weight modifiers for proportional widths [OK]
Common Mistakes:
  • Using Column for horizontal arrangement
  • Using fixed widths instead of weights
  • Applying padding instead of weight for size
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard