jetpack compose LazyLayout 参数未指定
jetpack compose LazyLayout parameters in not Specified
我想在 jetpack compose
中开发一个 LazyLayout
@ExperimentalFoundationApi
@Composable
fun LazyLayout(
itemsProvider: LazyLayoutItemsProvider!,
modifier: Modifier! = Modifier,
prefetchState: LazyLayoutPrefetchState? = null,
measurePolicy: (@ExtensionFunctionType LazyLayoutMeasureScope.(Constraints) ->
MeasureResult)?
): Unit
有两个必要的参数,itemsProvider
和measurePolicy
,这是文档中关于itemsProvider
参数的所有信息:
@param itemsProvider provides all the needed info about the items which could be used to compose and measure items as part of [measurePolicy].
我不知道如何为LazyLayout
提供这个参数。
知道它是如何工作的吗?
您必须像这样创建对象来仅提供“itemsProvider”参数:
LazyLayout(
itemsProvider = object : LazyLayoutItemsProvider {
override fun getContent(index: Int): @Composable () -> Unit {
return {
//your content
}
}
override val itemsCount: Int
get() = //count content
override fun getKey(index: Int): Any = index
override val keyToIndexMap: Map<Any, Int> = emptyMap()
override fun getContentType(index: Int): Any? = null
},
//modifier = modifier
//.padding(paddingValues)
//.verticalScroll(state = state, flingBehavior = NoFlingBehavior)
) { constraints ->
//do whatever you want
}
我想在 jetpack compose
中开发一个LazyLayout
@ExperimentalFoundationApi
@Composable
fun LazyLayout(
itemsProvider: LazyLayoutItemsProvider!,
modifier: Modifier! = Modifier,
prefetchState: LazyLayoutPrefetchState? = null,
measurePolicy: (@ExtensionFunctionType LazyLayoutMeasureScope.(Constraints) ->
MeasureResult)?
): Unit
有两个必要的参数,itemsProvider
和measurePolicy
,这是文档中关于itemsProvider
参数的所有信息:
@param itemsProvider provides all the needed info about the items which could be used to compose and measure items as part of [measurePolicy].
我不知道如何为LazyLayout
提供这个参数。
知道它是如何工作的吗?
您必须像这样创建对象来仅提供“itemsProvider”参数:
LazyLayout(
itemsProvider = object : LazyLayoutItemsProvider {
override fun getContent(index: Int): @Composable () -> Unit {
return {
//your content
}
}
override val itemsCount: Int
get() = //count content
override fun getKey(index: Int): Any = index
override val keyToIndexMap: Map<Any, Int> = emptyMap()
override fun getContentType(index: Int): Any? = null
},
//modifier = modifier
//.padding(paddingValues)
//.verticalScroll(state = state, flingBehavior = NoFlingBehavior)
) { constraints ->
//do whatever you want
}