【发布时间】:2022-12-08 03:34:49
【问题描述】:
我只是想始终偏移图像的确切数量,而不管用户的屏幕分辨率如何。
我这样试过:
var heightIs by remember { mutableStateOf(0f) }
Box(
modifier = Modifier
.fillMaxSize()
.aspectRatio(
ratio = 1f
).onGloballyPositioned { coordinates ->
heightIs = (coordinates.size.height.toFloat())
}
) {
Image(
painter = painterResource(id = R.drawable.base),
contentDescription = "Shadow",
modifier = Modifier.fillMaxSize()
)
Image(
painter = painterResource(id = R.drawable.top_mask_normal),
contentDescription = "Shadow Stencil",
colorFilter = ColorFilter.tint(color, BlendMode.SrcAtop),
modifier = Modifier
.fillMaxSize()
.offset(y = ((heightIs * 0.03).toInt()).dp)
)
}
但是我在不同的屏幕分辨率上得到不同的结果。 我要它确切地无论用户使用的是平板电脑还是 480x800 设备,每次都在同一位置
【问题讨论】:
-
您希望偏移量表示每个屏幕分辨率的相同距离,但您是根据屏幕高度计算偏移量?先生,你到底认为你在这里做什么?
标签: android kotlin android-jetpack-compose android-jetpack