【发布时间】:2022-01-01 00:11:07
【问题描述】:
- 我想将图像填充到页面的最大尺寸并填充应用栏下方的边缘。
- 我可以在不使用脚手架的情况下将图像填充到完整背景,但在这种情况下我需要使用脚手架。
- 截图附上问题以便更好地理解
- 你可以点击链接查看 enter image description here
@Composable
fun ScaffoldBackground() {
Scaffold(
topBar = {
TopAppBar(
modifier = Modifier
.fillMaxHeight(0.2f)
.clip(
shape = RoundedCornerShape(bottomEnd = 30.dp, bottomStart = 30.dp)
),
// Provide Title
title = {
Text(
text = "Dashboard",
)
}
)
},
) {
Box(
modifier = Modifier
.fillMaxSize()
) {
Image(
modifier = Modifier
.fillMaxSize(),
painter = painterResource(R.drawable.ic_launcher_background),
contentDescription = "background_image",
contentScale = ContentScale.FillBounds
)
}
}
}
【问题讨论】:
-
你想让你的图片放在 topAppBar 后面(图片的一部分会被剪掉)?
-
是的!!!!但是因为脚手架我们不能这样做
-
那么不要在顶层使用脚手架。使用盒子。在里面放你的脚手架和图片
fillMaxSize。 -
它会给出相同的响应...添加一个框不会改变任何东西
-
你能分享你的代码吗
标签: kotlin background android-jetpack-compose appbar scaffold