kotlin - 在Jetpack compose中Imageview的基础上调整Texview
问题描述
在左侧对齐 Imageview,在右侧对齐 3 个 textview,使图像的高度取决于纵横比,第一个文本视图应与 imageview 的顶部对齐,第三个 textview 的底部应与图像的底部对齐。这两个文本视图之间的空间应该给第二个文本视图。
@Preview
@Composable
fun ShowUi() {
Row
modifier = Modifier
.padding(10.dp)
.wrapContentHeight()
.fillMaxWidth()
) {
Box(
modifier = Modifier
.weight(7f)
.aspectRatio(1.77f)
.background(Color.Yellow)
) {
}
Column(
modifier = Modifier
.weight(3f)
.background(Color.Green)
) {
Text(
text = "Title 1",
fontSize = 20.sp,
maxLines = 1,
modifier = Modifier.background(Color.Green)
)
Text(
text = "You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.",
overflow = TextOverflow.Ellipsis,
modifier = Modifier.background(Color.Gray),
)
Text(
text = "PLAY NOW",
modifier = Modifier.background(Color.Green),
maxLines = 1
)
}
}
}
注意:不能在第二个 TextView 中使用 maxLines,因为可以显示的行数是动态的,即取决于第一个和第三个 textview 之间的可用空间。
解决方案
您可以考虑使用 Compose ConstraintLayout 来实现这一点。
https://developer.android.com/jetpack/compose/layouts/constraintlayout
推荐阅读
- azure - 无法在 azure 中创建 python 函数
- alexa - 显示接口与 APL
- laravel - 在视图上显示数据时尝试获取非对象的属性“column_name”
- asp.net-mvc - 如何将 Asp.net MVC Core 与 Asp.net Identity Core 和 WebAPi Core 一起使用?
- r - 避开ggplot中median_hilow的垂直线
- python - 名称 (?) 未定义
- solr - Apache solr 不仅仅从 Digital Ocean 中的特定 IP 响应
- android - 使用 FileProvider 加载照片导致 java.lang.IllegalArgumentException:无法找到包含的已配置根
- python - 计算机如何获得以下代码中的输出?
- java - 如何使用单个 java 服务从两个不同的表中验证用户