英文:
Horizontal pager misbehaving after the last item scroll
问题
I'm using the pageSize attribute with a fixed width of 282.dp but when scrolling after the last item the scroll takes while after returning to the normal position and if another vertical scroll happens it will stuck as stretched out (due to scrolling effect)
我的代码中使用了pageSize属性,固定宽度为282.dp,但在滚动到最后一个项目后,滚动会在返回到正常位置后花费一些时间,如果发生另一个垂直滚动,它将会卡在拉伸的状态下(由于滚动效果)
my pager composable
我的分页合成组件
@Composable
fun DealsPager(
deals: List<Deal>,
rentalDuration: String,
onClickDeal: (deal) -> Unit
) {
val pagerState = rememberPagerState()
HorizontalPager(
pageCount = deals.size,
state = pagerState,
pageSize = PageSize.Fixed(282.dp), // 这里是问题的原因
pageSpacing = 16.dp,
contentPadding = PaddingValues(horizontal = 16.dp)
) {
DealItem(
deal = deals[it],
duration = rentalDuration,
testTag = "deal list item $it",
onClick = onClickDeal
)
}
}
if I try to remove the pageSize is works fine and I need a way that it works normally with fixed size for item so more than one item shown per page
如果我尝试移除pageSize,它可以正常工作,但我需要一种方式,使其在项目上具有固定的大小,以便每页显示多个项目。
英文:
I'm using the pageSize attribute with a fixed width of 282.dp but when scrolling after the last item the scroll takes while after returning to the normal position and if another vertical scroll happens it will stuck as stretched out (due to scrolling effect)
my pager composable
@Composable
fun DealsPager(
deals: List<Deal>,
rentalDuration: String,
onClickDeal: (deal) -> Unit
) {
val pagerState = rememberPagerState()
HorizontalPager(
pageCount = deals.size,
state = pagerState,
pageSize = PageSize.Fixed(282.dp), // here is the problem cause
pageSpacing = 16.dp,
contentPadding = PaddingValues(horizontal = 16.dp)
) {
DealItem(
deal = deals[it],
duration = rentalDuration,
testTag = "deal list item $it",
onClick = onClickDeal
)
}
}
if I try to remove the pageSize is works fine and I need a way that it works normally with fixed size for item so more than one item shown per page
答案1
得分: 2
Use the column to set fixed size
Column(Modifier.width(282.dp)) {
HorizontalPager(
...
) {
...
}
}
英文:
Use the column to set fixed size
Column(Modifier.width(282.dp)) {
HorizontalPager(
...
) {
...
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论