Challenge - 5 Problems
LazyRow Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What will this LazyRow display?
Consider this Kotlin Compose code snippet using LazyRow. What will the user see on the screen?
Android Kotlin
LazyRow {
items(3) { index ->
Text(text = "Item $index")
}
}Attempts:
2 left
💡 Hint
LazyRow arranges items horizontally, and items(3) creates 3 items indexed 0 to 2.
✗ Incorrect
LazyRow creates a horizontal scrolling list. The items(3) block creates 3 items with indices 0, 1, and 2. Each item shows text "Item" plus its index.
📝 Syntax
intermediate2:00remaining
Which option correctly adds padding between items in LazyRow?
You want to add 8.dp horizontal space between each item in a LazyRow. Which code snippet does this correctly?
Attempts:
2 left
💡 Hint
Use horizontalArrangement with spacedBy to add space between items.
✗ Incorrect
The horizontalArrangement parameter with Arrangement.spacedBy(8.dp) adds 8.dp space between each item horizontally. Other options are invalid parameters.
❓ lifecycle
advanced2:00remaining
What happens if you scroll a LazyRow with many items?
You have a LazyRow with 1000 items. What is the behavior regarding item creation and memory?
Attempts:
2 left
💡 Hint
LazyRow is designed to be efficient with large lists by composing only visible items.
✗ Incorrect
LazyRow composes only the items visible on screen plus a small buffer. This optimizes memory and performance for large lists.
advanced
2:00remaining
How to detect which item is visible in LazyRow during scroll?
You want to know the index of the first visible item in a LazyRow while the user scrolls. Which approach is correct?
Attempts:
2 left
💡 Hint
LazyListState provides info about visible items and scroll position.
✗ Incorrect
rememberLazyListState() holds the scroll state of LazyRow. Its firstVisibleItemIndex property gives the index of the first visible item, which can be observed in LaunchedEffect or snapshotFlow.
🔧 Debug
expert3:00remaining
Why does this LazyRow not scroll horizontally?
This LazyRow code does not scroll horizontally as expected. What is the cause?
Android Kotlin
LazyRow(modifier = Modifier.fillMaxWidth()) {
items(5) { index ->
Text(text = "Item $index", modifier = Modifier.fillMaxWidth())
}
}Attempts:
2 left
💡 Hint
Check the width modifiers on items inside LazyRow.
✗ Incorrect
Using Modifier.fillMaxWidth() inside each item makes each item as wide as the LazyRow itself, so items stack vertically and no horizontal scrolling occurs. Items should have fixed or wrap content width.