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

相关推荐
Android-Flutter18 小时前
Android 内存泄漏详解
android·kotlin
Android-Flutter19 小时前
android Handler , Looper , Message , MessageQueue 详解
android·kotlin
阿pin21 小时前
Android随笔-kotlin Flow
android·kotlin·flow
松仔log21 小时前
JetPack——Hilt
android·java·开发语言·kotlin
chjif1 天前
Android 设备管控开发实战:常见保活与拉活方案怎么组合,实测能到什么程度?
android·kotlin
XiaoLeisj1 天前
Kotlin Flow 常用操作符:数据变换 map、filter、onEach,时间控制 debounce、sample,终端聚合 reduce、fold
android·kotlin·android jetpack·协程·响应式编程·flow
Kapaseker1 天前
小白都看得懂的 Skill 教程 - 创建第一个 Skill
android·kotlin·vibecoding
zhangphil1 天前
Android BitmapFactory实现AOSP ContentResolver.loadThumbnail快速取小缩略图,Kotlin
android·kotlin
Android-Flutter1 天前
android 生命周期管理,继承Activity,不是AppCompatActivity
android·kotlin
XiaoLeisj2 天前
Kotlin Flow:冷流收集、并行订阅、emit 推送、delay 延迟、collect 全量收集与 collectLatest 的实时数据处理
android·kotlin·android jetpack·协程·flow