![](/img/trans.png)
[英]Resistance with scroll in HorizontalPager in Jetpack Compose
[英]HorizontalPager is ignoring itemSpacing and overriding content in Jetpack Compose
我有一个带有 currentPage 焦点效果的 HorizontalPager(来自 Accompanist)。 在模拟器上,它可以正常工作,并且具有我想要的正确间距,但是,在智能手机上,它不遵守 itemSpacing 并完全忽略它,与右侧的寻呼机项目重叠。 有没有办法让这个寻呼机始终具有相同的间距,而不管设备如何? 或者,至少,右边的项目不重叠并且主要项目与其他两个项目重叠?
下面是正在发生的事情和我想要的行为的一些屏幕截图:
正确的行为(在模拟器上工作):
错误行为和问题(在物理设备上工作):
代码:
HorizontalPager(
state = state,
count = items.count(),
contentPadding = PaddingValues(horizontal = 72.dp),
itemSpacing = 10.dp,
modifier = modifier.padding(top = 16.dp)
) { page ->
Card(
shape = RectangleShape,
modifier = Modifier
.graphicsLayer {
// Calculate the absolute offset for the current page from the
// scroll position. We use the absolute value which allows us to mirror
// any effects for both directions
val pageOffset = calculateCurrentOffsetForPage(page).absoluteValue
// We animate the scaleX + scaleY, between 85% and 100%
lerp(
start = 0.85f,
stop = 1f,
fraction = 1f - pageOffset.coerceIn(0f, 1f)
).also { scale ->
scaleX = scale
scaleY = scale
}
// We animate the alpha, between 50% and 100%
alpha = lerp(
start = 0.6f,
stop = 1f,
fraction = 1f - pageOffset.coerceIn(0f, 1f)
)
}
.requiredWidth(284.dp)
.requiredHeight(168.dp)
//.coloredShadow(Shadow, 0.28f)
) {
// content
}
}
可以提供任何其他必要的代码,请告诉我。
您应该使用 how to support different screen sizes in android with jetpack compose,您可以在其中为不同的配置定义尺寸。 同上可以参考这个教程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.