[英]HorizontalPager is ignoring itemSpacing and overriding content in Jetpack Compose
I have a HorizontalPager (from Accompanist) with a currentPage focus effect.我有一个带有 currentPage 焦点效果的 HorizontalPager(来自 Accompanist)。 On the emulator, it works correctly and with the correct spacing that I intend, however, on a smartphone, it doesn't respect the itemSpacing and completely ignores it, overlapping the pager items on the right.
在模拟器上,它可以正常工作,并且具有我想要的正确间距,但是,在智能手机上,它不遵守 itemSpacing 并完全忽略它,与右侧的寻呼机项目重叠。 Is there any way to make this pager always have the same spacing regardless of the device?
有没有办法让这个寻呼机始终具有相同的间距,而不管设备如何? Or, at least, that the item on the right does not overlap and that the main item overlaps the other two?
或者,至少,右边的项目不重叠并且主要项目与其他两个项目重叠?
Below a few screenshots of what is happening and the behavior that I want:下面是正在发生的事情和我想要的行为的一些屏幕截图:
Correct behavior (working on emulator):正确的行为(在模拟器上工作):
Wrong behavior & problem (working on physical device):错误行为和问题(在物理设备上工作):
Code:代码:
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
}
}
Any additional necessary code can be provided, just let me know.可以提供任何其他必要的代码,请告诉我。
You should be using how to support different screen sizes in android with jetpack compose, in which you can define dimensions for different configurations.您应该使用 how to support different screen sizes in android with jetpack compose,您可以在其中为不同的配置定义尺寸。 You can refer to this tutorial on the same
同上可以参考这个教程
https://proandroiddev.com/supporting-different-screen-sizes-on-android-with-jetpack-compose-f215c13081bd https://proandroiddev.com/supporting-different-screen-sizes-on-android-with-jetpack-compose-f215c13081bd
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.