Files
AndroidJetpack/Jetpack-Compose-Playground/docs/foundation/lazyrow.md
T
2026-07-15 16:57:36 +08:00

55 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!---
This is the API of version 1.2.0
-->
# LazyRow
A [LazyRow]({{ site.composedoc }}/foundation/lazy/package-summary#lazyrow) is a horizontal scrolling list that only composes and lays out the currently visible items.
It's similar to a horizontal Recyclerview in the classic Android View system.
<p align="left">
<img src ="{{ site.images }}/foundation/lazyrow/lazyrow.png" height=100 width=300 />
</p>
```kotlin
@Composable
fun LazyRowDemo() {
val list = listOf(
"A", "B", "C", "D"
) + ((0..100).map { it.toString() })
LazyRow(modifier = Modifier.fillMaxHeight()) {
items(items = list, itemContent = { item ->
Log.d("COMPOSE", "This get rendered $item")
when (item) {
"A" -> {
Text(text = item, style = TextStyle(fontSize = 80.sp))
}
"B" -> {
Button(onClick = {}) {
Text(text = item, style = TextStyle(fontSize = 80.sp))
}
}
"C" -> {
//Do Nothing
}
"D" -> {
Text(text = item)
}
else -> {
Text(text = item, style = TextStyle(fontSize = 80.sp))
}
}
})
}
}
```
## See also:
* [Official Docs]({{ site.composedoc }}/foundation/lazy/package-summary#lazyrow)
* [Full Example Code]({{ site.samplefolder }}/foundation/LazyRowDemo.kt)
<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/1ANt65eoNhQ" title="Lazy layouts in Compose" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
[Lazy and amazy Lazy layouts in Compose](https://www.droidcon.com/2022/08/01/lazy-and-amazy-lazy-layouts-in-compose/)