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.