gpt4 book ai didi

android - Jetpack Compose 的 LazyVerticalGrid 是否有 span 策略

转载 作者:行者123 更新时间:2023-12-04 12:30:11 29 4
gpt4 key购买 nike

我有一个带有 2 个单元格的 LazyVerticalGrid。

LazyVerticalGrid(
cells = GridCells.Fixed(2),
content = {
items(moviePagingItems.itemCount) { index ->
val movie = moviePagingItems[index] ?: return@items
MovieItem(movie, Modifier.preferredHeight(320.dp))
}
renderLoading(moviePagingItems.loadState)
}
)
enter image description here
我正在尝试使用 LazyGridScope 显示全宽加载的 fillParentMaxSize修饰符。
fun LazyGridScope.renderLoading(loadState: CombinedLoadStates) {
when {
loadState.refresh is LoadState.Loading -> {
item {
LoadingColumn("Fetching movies", Modifier.fillParentMaxSize())
}
}
loadState.append is LoadState.Loading -> {
item {
LoadingRow(title = "Fetching more movies")
}
}
}
}
但由于我们有 2 个单元格,加载可以占据屏幕的一半。像这样:
enter image description here
有没有办法让我的加载 View 占据全宽?

最佳答案

喷气背包撰写 1.1.0-beta03版本包括对 LazyVerticalGrid 的水平跨度支持.
这是示例用法:

private const val CELL_COUNT = 2

private val span: (LazyGridItemSpanScope) -> GridItemSpan = { GridItemSpan(CELL_COUNT) }

LazyVerticalGrid(
cells = GridCells.Fixed(CELL_COUNT),
content = {
items(moviePagingItems.itemCount) { index ->
val movie = moviePagingItems.peek(index) ?: return@items
Movie(movie)
}
renderLoading(moviePagingItems.loadState)
}
}

private fun LazyGridScope.renderLoading(loadState: CombinedLoadStates) {
if (loadState.append !is LoadState.Loading) return

item(span = span) {
val title = stringResource(R.string.fetching_more_movies)
LoadingRow(title = title)
}
}
此答案的代码示例可在以下位置找到: Jetflix/MoviesGrid.kt

关于android - Jetpack Compose 的 LazyVerticalGrid 是否有 span 策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65981114/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com