Jetpack Compose_Alignment对其+Arrangement排列

文章目录

1.Alignment 对齐

1.1Alignment 对齐方式

Alignment

类型 对齐方式 说明
Alignment TopStart 顶部左对齐
TopCenter 顶部居中对齐
TopEnd 顶部右对齐
CenterStart 居中左对齐
Center 居中
CenterEnd 居中右对齐
BottomStart 底部左对齐
BottomCenter 底部居中
BottomEnd 底部右对齐
Alignment.Vertical Top 竖直的置顶
CenterVertically 竖直的居中
Bottom 竖直的置底
Alignment.Horizontal Start 水平的置左
CenterHorizontally 水平的居中
End 水平的置右

疑问:为什么有 Alignment 了,还需要有 Alignment.VerticalAlignment.Horizontal 呢?

因为有些控件,如 Row 只能调整竖直方向上的对齐方式,水平方向上调的是 Arrangement 排列,因此对齐枚举需要限制为特定方向上的


1.2AbsoluteAlignment 绝对对齐

AbsoluteAlignment

不知道布局方向的常见对齐方式的集合。

类型 对齐方式 说明
Alignment TopLeft 左上角
TopRight 右上角
CenterLeft 居中左侧
CenterRight 居中右侧
BottomLeft 底部左侧
BottomRight 底部右侧
Alignment.Horizontal Left 水平方向左侧
Right 水平方向右侧

当不知道是横向还是纵向布局方式时使用,暂时还没想到应用场景。(欢迎评论补充)


1.3BiasAlignment 偏差对齐

BiasAlignment

-1: 表示 start/top

0: 表示 center

1: 表示 end/bottom

kotlin 复制代码
data class BiasAlignment(
    val horizontalBias: Float, // 水平方向对齐方式
    val verticalBias: Float // 竖直方向对齐方式
)

1.4BiasAbsoluteAlignment偏差绝对对齐

BiasAbsoluteAlignment

-1: 表示对齐到左上角

0: 表示居中

1: 表示右下角

就是在 左上角右下角 这条斜线上对齐

kotlin 复制代码
data class BiasAbsoluteAlignment(
    private val horizontalBias: Float,
    private val verticalBias: Float
)

2.Arrangement 排列

2.1Arrangement 排列方式

Arrangement

对齐方式 说明
Equal Weight 等宽/高
Space Between 等间距
Space Around 每个item等padding
Space Evenly 每个item等margin
End 尾部对其
Center 居中
Start 头部对其

2.2Arrangement.Horizontal

如:RowhorizontalArrangement

2.3Arrangement.Vertical

如:ColumnverticalArrangement


参考:
androidx.compose.foundation.layout
Componse教程 | 关于 Alignment与Arrangement

相关推荐
Fushize9 小时前
多模块架构下的依赖治理:如何避免 Gradle 依赖地狱
android·架构·kotlin
Jomurphys10 小时前
Kotlin - 类型别名 typealias
android·kotlin
zh_xuan10 小时前
kotlin lazy委托异常时执行流程
开发语言·kotlin
我有与与症15 小时前
从页面加载过程看 Kuikly 的多线程架构
kotlin
JMchen12319 小时前
Android UDP编程:实现高效实时通信的全面指南
android·经验分享·网络协议·udp·kotlin
JMchen12320 小时前
Android网络安全实战:从HTTPS到双向认证
android·经验分享·网络协议·安全·web安全·https·kotlin
JMchen1231 天前
Android后台服务与网络保活:WorkManager的实战应用
android·java·网络·kotlin·php·android-studio
儿歌八万首2 天前
硬核春节:用 Compose 打造“赛博鞭炮”
android·kotlin·compose·春节
消失的旧时光-19432 天前
从 Kotlin 到 Dart:为什么 sealed 是处理「多种返回结果」的最佳方式?
android·开发语言·flutter·架构·kotlin·sealed
有位神秘人2 天前
kotlin与Java中的单例模式总结
java·单例模式·kotlin