gpt4 book ai didi

android - 使用 Jetpack Compose 将文本换行到下一行

转载 作者:行者123 更新时间:2023-12-04 23:49:05 31 4
gpt4 key购买 nike

enter image description here我创建了一个约束布局

 ConstraintLayout(
Modifier
.fillMaxWidth()
.wrapContentHeight()
) {

Image(
painter = rememberImagePainter(it.photoUrl.toString()),
modifier = Modifier
.constrainAs(photo) {
start.linkTo(parent.start, margin = 30.dp)
top.linkTo(parent.top, margin = 30.dp)
}
.width(130.dp)
)

Column(
modifier = Modifier
.constrainAs(holder) {
start.linkTo(photo.end, margin = 30.dp)
top.linkTo(photo.top)
bottom.linkTo(photo.bottom)
end.linkTo(parent.end, margin = 30.dp)
}
.fillMaxWidth()
.wrapContentHeight(),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
modifier = Modifier
.wrapContentWidth()
.wrapContentHeight(),
text = "Lorem Ipsu auto text ator..."
)
}
如您所见,长文本不适合布局。如何将文本换行到下一行?我试图将 wrapContentWidht() 更改为 fillMaxParentWidth 但 id 没有帮助。

最佳答案

您可以使用 width = Dimension.fillToConstraints将宽度限制为可用空间。
constrainAs 内堵塞
在您的示例中:

.constrainAs(holder) {
start.linkTo(photo.end, margin = 30.dp)
top.linkTo(photo.top)
bottom.linkTo(photo.bottom)
end.linkTo(parent.end, margin = 30.dp)
width = Dimension.fillToConstraints
}

关于android - 使用 Jetpack Compose 将文本换行到下一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69499129/

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