Android 如何获取顶部/正面有文字的图像?(谷歌教室主页图像格式)
我想制作一个上面有文本的图像,就像谷歌教室一样。但首先我想测试图像,然后测试文本。相反,我得到了与文本重叠的图像。 然后我将图像代码移到文本之后。如何获得简单的G教室格式Android 如何获取顶部/正面有文字的图像?(谷歌教室主页图像格式),android,android-jetpack,android-jetpack-compose,Android,Android Jetpack,Android Jetpack Compose,我想制作一个上面有文本的图像,就像谷歌教室一样。但首先我想测试图像,然后测试文本。相反,我得到了与文本重叠的图像。 然后我将图像代码移到文本之后。如何获得简单的G教室格式 要将文本放在图像顶部,可以使用框,它类似于旧的FrameLayout 我不确定您想要实现什么,但如果smth喜欢这样: 然后你可以这样做: Surface( shape = RoundedCornerShape(8.dp), modifier = Modifier .preferredHeight(
要将文本放在图像顶部,可以使用框,它类似于旧的FrameLayout 我不确定您想要实现什么,但如果smth喜欢这样: 然后你可以这样做:
Surface(
shape = RoundedCornerShape(8.dp),
modifier = Modifier
.preferredHeight(128.dp)
.clickable(onClick = {})
) {
Box {
Image(
vectorResource(id = R.drawable.ic_launcher_background),
alpha = imageAlpha,
contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize()
)
Column(modifier = Modifier.padding(16.dp)) {
Text(
"Alfred Sisley",
fontWeight = FontWeight.Bold,
style = MaterialTheme.typography.h6)
ProvideEmphasis(emphasis = EmphasisAmbient.current.medium) {
Text("3 minutes ago", style = MaterialTheme.typography.body2)
}
Spacer(modifier = Modifier.weight(1f))
Text(text = "Footer", style = MaterialTheme.typography.body1)
}
}
}
使用
1.0.0-beta02
可以使用框作为父容器。
比如:
Box(modifier = Modifier.height(IntrinsicSize.Max))
{
Image(
painterResource(id = R.drawable.xx),
"contentDescription",
alpha = 0.8f,
modifier = Modifier.requiredHeight(100.dp)
)
Column(
modifier = Modifier.fillMaxHeight(),
verticalArrangement = Arrangement.Bottom) {
Text("Alfred Sisley",
fontWeight = FontWeight.Bold)
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
Text("3 minutes ago", style = MaterialTheme.typography.body2)
}
}
}
我想你指的是卡片而不是盒子
Box(modifier = Modifier.height(IntrinsicSize.Max))
{
Image(
painterResource(id = R.drawable.xx),
"contentDescription",
alpha = 0.8f,
modifier = Modifier.requiredHeight(100.dp)
)
Column(
modifier = Modifier.fillMaxHeight(),
verticalArrangement = Arrangement.Bottom) {
Text("Alfred Sisley",
fontWeight = FontWeight.Bold)
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
Text("3 minutes ago", style = MaterialTheme.typography.body2)
}
}
}