0
0
Android Kotlinmobile~20 mins

LazyRow for horizontal lists in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
LazyRow Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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")
  }
}
AA horizontal list showing: Item 0, Item 1, Item 2
BAn empty screen with no items
CA horizontal list showing only one item: Item 3
DA vertical list showing: Item 0, Item 1, Item 2
Attempts:
2 left
💡 Hint
LazyRow arranges items horizontally, and items(3) creates 3 items indexed 0 to 2.
📝 Syntax
intermediate
2: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?
ALazyRow(spacing = 8.dp) { items(5) { Text("Item") } }
BLazyRow(padding = PaddingValues(horizontal = 8.dp)) { items(5) { Text("Item") } }
CLazyRow(horizontalPadding = 8.dp) { items(5) { Text("Item") } }
DLazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) { items(5) { Text("Item") } }
Attempts:
2 left
💡 Hint
Use horizontalArrangement with spacedBy to add space between items.
lifecycle
advanced
2: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?
AAll 1000 items are composed and kept in memory at once, causing high memory use.
BOnly visible items are composed and kept in memory; off-screen items are disposed to save memory.
CLazyRow loads items in batches of 100 and discards others immediately.
DLazyRow duplicates items to fill the screen even if fewer items exist.
Attempts:
2 left
💡 Hint
LazyRow is designed to be efficient with large lists by composing only visible items.
navigation
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?
AUse rememberLazyListState() and check state.firstVisibleItemIndex inside LaunchedEffect.
BUse Modifier.onGloballyPositioned to get item positions and calculate visible index manually.
CUse a ScrollListener on LazyRow to get scroll offset and guess visible item.
DLazyRow does not support detecting visible items during scroll.
Attempts:
2 left
💡 Hint
LazyListState provides info about visible items and scroll position.
🔧 Debug
expert
3: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())
  }
}
Aitems(5) is too few items to enable scrolling.
BLazyRow requires a fixed height modifier to enable scrolling.
CEach item uses fillMaxWidth(), so items take full width and block horizontal scrolling.
DLazyRow needs horizontalScroll modifier to scroll.
Attempts:
2 left
💡 Hint
Check the width modifiers on items inside LazyRow.