水平分页器在滚动到最后一项后出现问题。

huangapple go评论45阅读模式
英文:

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&lt;Deal&gt;,
    rentalDuration: String,
    onClickDeal: (deal) -&gt; 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 = &quot;deal list item $it&quot;,
            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(
      ...
    ) {
       ...
    }
}

huangapple
  • 本文由 发表于 2023年5月10日 18:17:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76217243.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定