gpt4 book ai didi

android - Jetpack Compose 水平对齐问题

转载 作者:行者123 更新时间:2023-12-04 03:22:13 25 4
gpt4 key购买 nike

enter image description here
我需要将图像和 TextView 定位到卡片的开头,子列水平居中对齐,但是正如您从照片中看到的那样,列以某种方式被拉伸(stretch)了放置图像的屏幕宽度和中心的 TextView 。任何人都可以看到我的代码有任何问题吗?

@Composable
fun TrainerCard(profile: TrainerProfile) {
Card(modifier = Modifier
.height(180.dp)
.fillMaxWidth()
.padding(4.dp)) {
Column(modifier = Modifier
.fillMaxHeight()
.width(120.dp)
.border(1.dp, color = Color.Red),
horizontalAlignment = Alignment.CenterHorizontally) {
Image(
modifier = Modifier
.size(120.dp)
.padding(top = 4.dp, start = 4.dp),
painter = painterResource(R.drawable.pokepals_logo),
contentDescription = null
)
Text(
text = profile.trainerName,
style = MaterialTheme.typography.subtitle1)
}
}
}

最佳答案

在您的 Column添加 wrapContentWidth(Alignment.Start)修饰符:

    Column(modifier = Modifier
.fillMaxHeight()
.width(120.dp)
.wrapContentWidth(Alignment.Start)
.border(1.dp, color = Color.Red),
horizontalAlignment = Alignment.CenterHorizontally
)
enter image description here

关于android - Jetpack Compose 水平对齐问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68308313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com