Skip to content

Instantly share code, notes, and snippets.

@lisonge
Last active March 13, 2025 12:06
Show Gist options
  • Save lisonge/b689ea150c7df8ae2618c4f73203ad9e to your computer and use it in GitHub Desktop.
Save lisonge/b689ea150c7df8ae2618c4f73203ad9e to your computer and use it in GitHub Desktop.
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.itemsIndexed
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.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@Composable
private fun ListDemo() {
var titles = listOf(2, 4, 200)
LazyColumn(
modifier = Modifier
.background(Color.White)
.fillMaxSize(),
) {
itemsIndexed(titles) { index, item ->
Box(
modifier = Modifier
.padding(12.dp)
.fillMaxWidth()
) {
Row(
modifier = Modifier.matchParentSize(),
) {
Column(
modifier = Modifier
.fillMaxHeight()
.width(32.dp),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Spacer(
modifier = Modifier
.fillMaxHeight()
.width(4.dp)
.background(Color.Green)
)
}
}
Column {
Spacer(
modifier = Modifier
.size(32.dp)
.background(Color.Red)
)
Row(
modifier = Modifier
.fillMaxWidth()
.padding(start = 32.dp)
) {
Column(
modifier = Modifier
.weight(1f),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Row(
modifier = Modifier
.fillMaxWidth()
) {
Text(
text = "Time:",
fontSize = 14.sp,
color = Color.Gray,
modifier = Modifier
.width(100.dp)
)
Spacer(Modifier.width(4.dp))
Text(
text = "2023-03-02 18:34:07",
fontSize = 14.sp,
color = Color.Gray
)
}
val images = List(item) { it.toString() }
LazyVerticalGrid(
columns = GridCells.Fixed(3),
horizontalArrangement = Arrangement.spacedBy(6.dp),
verticalArrangement = Arrangement.spacedBy(6.dp),
modifier = Modifier
.fillMaxWidth()
.heightIn(
min = 0.dp,
max = 300.dp
)
) {
items(images) { pic ->
Box(
modifier = Modifier
.aspectRatio(1f)
.background(Color.Gray)
) {
Text(
text = pic
)
}
}
}
}
}
}
}
Spacer(modifier = Modifier.height(12.dp))
}
}
}
@Preview
@Composable
fun ListDemoPreview() {
ListDemo()
}
@lisonge
Copy link
Author

lisonge commented Mar 13, 2025

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment