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

相关推荐
帅次3 小时前
Compose 入门:@Composable、组合与重组
android·kotlin·gradle·android jetpack·compose·composable
Junerver4 小时前
Kotlin - 约定contract
kotlin
Junerver5 小时前
使用datetime更加优雅地在kotlin中处理时间
kotlin
装杯让你飞起来啊7 小时前
第 4 周 Unit 2:Jetpack Compose 状态、按钮、计数器与小费计算器
windows·microsoft·kotlin·安卓
Kapaseker12 小时前
MVVM 旧城改造,边界划分各有招
android·kotlin
装杯让你飞起来啊1 天前
第 2 周 Day 5-6:综合小游戏 —— 学生成绩管理系统
windows·microsoft·kotlin
装杯让你飞起来啊1 天前
Kotlin List / Array 与 for 循环
开发语言·kotlin·list
装杯让你飞起来啊1 天前
混合练习 —— 猜数字游戏
windows·游戏·kotlin
装杯让你飞起来啊1 天前
Kotlin 条件判断 if / when 与智能转换 smart cast
开发语言·python·kotlin
pengyu1 天前
【Kotlin 协程修仙录 · 金丹境 · 初阶】 | 并发艺术:async/await 与并发组合的优雅之道
android·kotlin