With the code below only the left quadrants appear. I still can't figure out the solution.
package com.example.composequadrant
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.composequadrant.ui.theme.ComposeQuadrantTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ComposeQuadrantTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Quadrants(
titleUpperRight = "Text composable",
textUpperRight = "Displays text and follows the recommended Material Design guidelines.",
colorUpperRight = Color(0xFFEADDFF),
titleUpperLeft = "Image composable",
textUpperLeft = "Creates a composable that lays out and draws a given Painter class object.",
colorUpperLeft = Color(0xFFD0BCFF),
titleBottomRight = "Row composable",
textBottomRight = "A layout composable that places its children in a horizontal sequence.",
colorBottomRight = Color(0xFFB69DF8),
titleBottomLeft = "Column composable",
textBottomLeft = "A layout composable that places its children in a vertical sequence.",
colorBottomLeft = Color(0xFFF6EDFF)
)
}
}
}
}
}
@Composable
fun ComposableInfoCard(title: String, description: String,
color: Color, modifier: Modifier = Modifier) {
// Setup background, padding and size modifiers. Also, set the alignment to center - vertically as well
// as horizontally
Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
modifier = modifier
.fillMaxSize()
.background(color)
.padding(16.dp)
) {
Text(
text = title,
fontWeight = FontWeight.Bold,
modifier = Modifier.padding(bottom = 16.dp)
)
Text(
text = description,
textAlign = TextAlign.Justify,
)
}
}
@Composable
fun Quadrants(titleUpperRight: String, textUpperRight: String, colorUpperRight: Color,
titleUpperLeft: String, textUpperLeft: String, colorUpperLeft: Color,
titleBottomRight: String, textBottomRight: String, colorBottomRight: Color,
titleBottomLeft: String, textBottomLeft: String, colorBottomLeft: Color,
modifier: Modifier = Modifier) {
Column(modifier = modifier) {
Row(modifier = Modifier.weight(1f)) {
ComposableInfoCard(
title = titleUpperRight,
description = textUpperRight,
color = colorUpperRight
)
ComposableInfoCard(
title = titleUpperLeft,
description = textUpperLeft,
color = colorUpperLeft
)
}
Row(modifier = Modifier.weight(1f)) {
ComposableInfoCard(
title = titleBottomRight,
description = textBottomRight,
color = colorBottomRight
)
ComposableInfoCard(
title = titleBottomLeft,
description = textBottomLeft,
color = colorBottomLeft
)
}
}
}
@Preview(showBackground = true)
@Composable
fun QuadrantPreview() {
ComposeQuadrantTheme {
Quadrants("1,1,1",
"1,1,2",
Color(0xFFEADDFF),
"1,2,1",
"1,2,2",
Color(0xFFD0BCFF),
"1,2,1",
"1,2,2",
Color(0xFFB69DF8),
"2,2,1",
"2,2,2",
Color(0xFFF6EDFF)
)
}
}