2023/10/22
Topics
Compose
- Compose で
nestedScrollEnabled = false
がやりたい
Column(modifier = Modifier.verticalScroll())
の中に LazyColumn
ができないっぽい
- item で header として1つのレイアウトとして使ってねとのことらしい
- リストに header や footer はわかるけど、レイアウトの中にリストがあるデザインの場合なんだかなぁ...ってなるな
java.lang.IllegalStateException: Vertically scrollable component was measured with an infinity maximum height constraints, which is disallowed. One of the common reasons is nesting layouts like LazyColumn and Column(Modifier.verticalScroll()). If you want to add a header before the list of items please add a header as a separate item() before the main items() inside the LazyColumn scope. There are could be other reasons for this to happen: your ComposeView was added into a LinearLayout with some weight, you applied Modifier.wrapContentSize(unbounded = true) or wrote a custom layout. Please try to remove the source of infinite constraints in the hierarchy above the scrolling container.
- LazyVerticalGrid で
spanSize = 2
とかで header を用意している場合に、items にだけ ContentPadding がほしくても header にもかかっちゃうので計算する必要がありそうでそれもどうなんだろう...
spanSize = 3
とかになったらややこしいな
LazyVerticalGrid(
columns = GridCells.Fixed(2),
verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
itemsIndexed(items) { index, item ->
Item(
modifier = modifier
.padding(
start = if (index.isEven()) 8.dp else 0.dp,
end = if (index.isEven()) 0.dp else 8.dp
)
)
}
}
private fun Int.isEven() = this % 2 == 0
リストとグリッド Android Developers