属性总表
按真实开发频率汇总:Modifier 链上的修饰符 + 各组件高频参数。先掌握「常用」,「偶尔」遇到再查。
常用写界面几乎天天用
偶尔特定场景再查
顺序敏感:Modifier 从外到内(或按官方「谁先谁包住」)会影响热区与背景范围。细节回
Modifier。
Modifier · 尺寸与占据
| 属性 | 频率 | 作用 | 注意 | 链接 |
size / width / height | 常用 | 固定宽高 | 过大可能裁切父约束 | Modifier |
fillMaxWidth / fillMaxHeight / fillMaxSize | 常用 | 吃满父约束 | 百分比可用 fillMaxWidth(0.5f) | Modifier |
wrapContentWidth / Height / Size | 偶尔 | 按内容收缩并对齐 | 常配合 align | Modifier |
defaultMinSize / requiredSize | 偶尔 | 最小尺寸 / 强制尺寸 | required 可能突破约束 | Modifier |
aspectRatio | 常用 | 固定宽高比 | 封面图、视频占位 | Modifier |
weight | 常用 | Row/Column 比例分空间 | 仅直接子项 | 布局 |
align(Box) / alignBy | 常用 | 子项对齐 | 作用域不对会编不过 | 布局 |
matchParentSize | 偶尔 | Box 内铺满已测兄弟 | 仅 BoxScope | 布局 |
Modifier · 边距与背景
| 属性 | 频率 | 作用 | 注意 | 链接 |
padding | 常用 | 内边距 | 与 background 顺序敏感 | Modifier |
background | 常用 | 背景色 / brush | 圆角要带 shape 或先 clip | Modifier |
border | 常用 | 描边 | 同样要 shape | Modifier |
clip | 常用 | 裁剪外形 | 图片圆角常 clip | Modifier |
shadow | 偶尔 | 阴影 | 常与 clip/background 搭配;Card 自带 elevation | Modifier |
alpha | 常用 | 透明度 | 禁用态常用 0.38 | Modifier |
Modifier · 点击与手势
| 属性 | 频率 | 作用 | 注意 | 链接 |
clickable | 常用 | 单击 | 热区与 padding 顺序;无障碍要有说明 | Modifier |
combinedClickable | 偶尔 | 单击 + 长按 + 双击 | 列表项长按菜单 | Modifier |
selectable / toggleable | 偶尔 | 可选中 / 可切换语义 | 比裸 clickable 更利于无障碍 | 主题 |
indication / MutableInteractionSource | 偶尔 | 涟漪 / 交互源 | 自定义按压反馈 | Modifier |
pointerInput / detectTapGestures | 偶尔 | 底层手势 | 复杂手势再下钻 | Modifier |
| 属性 | 频率 | 作用 | 注意 | 链接 |
verticalScroll / horizontalScroll | 常用 | 短内容可滚 | 长列表用 Lazy,勿硬塞 | Modifier |
nestedScroll | 偶尔 | 嵌套滚动协作 | 折叠顶栏等 | Modifier |
offset | 偶尔 | 偏移绘制 | 不占布局;别当间距 | Modifier |
rotate / scale / graphicsLayer | 常用 | 旋转缩放 / 图层 | 常接 AsState / Infinite | 动画 |
animateContentSize | 常用 | 内容变了容器跟着长 | 展开更多、表单报错 | 动画 |
animateItem() | 常用 | Lazy 条目进出与位移 | 必须配稳定 key | 动画 |
sharedElement / sharedBounds | 偶尔 | 共享元素 / 共享边框 | 需 SharedTransitionLayout | 动画 |
zIndex | 偶尔 | 同级叠放顺序 | Box 内兄弟 | 布局 |
imePadding | 常用 | 键盘避让 | 表单页几乎必备 | Modifier |
statusBarsPadding / navigationBarsPadding / systemBarsPadding | 常用 | 系统栏内边距 | Scaffold 常已处理一部分 | 结构 |
windowInsetsPadding / safeDrawingPadding | 偶尔 | 精细 Insets | 全面屏 / 刘海 | 结构 |
Modifier · 无障碍与测试
| 属性 | 频率 | 作用 | 注意 | 链接 |
semantics / clearAndSetSemantics | 偶尔 | 自定义语义树 | 测试与读屏 | 主题 · 测试 |
testTag | 偶尔 | UI 测试定位 | Compose Test | 测试 |
contentDescription(组件参数) | 常用 | 图标/图片读屏名 | 装饰图传 null | 主题 |
组件参数 · 文本与图标
| 参数 | 频率 | 作用 | 链接 |
Text(text, style, color, textAlign) | 常用 | 内容与字阶 | 基础 |
Text(maxLines, overflow, softWrap) | 常用 | 省略与换行 | 基础 |
AnnotatedString / inlineContent | 偶尔 | 富文本 / 行内图 | 基础 |
Icon(imageVector, contentDescription, tint) | 常用 | 矢量图标 | 基础 |
Image(painter, contentScale, contentDescription) | 常用 | 本地图适配 | 基础 |
AsyncImage(model, placeholder, error) | 常用 | 网络图三态 | 基础 |
组件参数 · 输入与按钮
| 参数 | 频率 | 作用 | 链接 |
TextField(value, onValueChange) | 常用 | 受控输入(必写) | 基础 |
label / placeholder / supportingText | 常用 | 标签与辅助文案 | 基础 |
leadingIcon / trailingIcon | 常用 | 前后图标 | 基础 |
isError / enabled / readOnly | 常用 | 错误 / 禁用 / 只读 | 基础 |
singleLine / maxLines / keyboardOptions | 常用 | 行数与键盘类型 | 基础 |
visualTransformation(密码) | 偶尔 | 遮罩显示 | 基础 |
Button(onClick, enabled, colors, shape) | 常用 | 点击与样式 | 基础 |
Switch/Checkbox(checked, onCheckedChange) | 常用 | 受控开关勾选 | 基础 |
Slider(value, onValueChange, valueRange) | 偶尔 | 滑动取值 | 基础 |
组件参数 · 列表与刷新
| 参数 | 频率 | 作用 | 链接 |
LazyColumn(state, contentPadding, reverseLayout) | 常用 | 列表状态与边距 | 列表 |
items(..., key = , contentType = ) | 常用 | 稳定 identity / 复用 | 列表 |
stickyHeader { } | 偶尔 | 粘性分组头 | 列表 |
PullToRefreshBox(isRefreshing, onRefresh) | 常用 | 下拉刷新 | 列表 |
indicator + PullToRefreshState.distanceFraction | 偶尔 | 自定义下拉动画 | 列表 |
PagingConfig(pageSize, prefetchDistance) | 常用 | 每页条数 / 预加载 | 列表 |
collectAsLazyPagingItems / loadState / refresh() | 常用 | 收集分页与三态 | 列表 |
HorizontalPager(state, pageCount / pageSize) | 常用 | 页指示与翻页 | 列表 |
GridCells.Fixed / Adaptive | 常用 | 网格列数策略 | 列表 |
组件参数 · 结构与导航
| 参数 | 频率 | 作用 | 链接 |
Scaffold(topBar, bottomBar, snackbarHost, floatingActionButton) | 常用 | 页面槽位 | 结构 |
Scaffold { paddingValues -> … } | 常用 | 内容避让顶底栏 | 结构 |
TopAppBar(title, navigationIcon, actions, colors) | 常用 | 顶栏内容 | 结构 |
NavigationBarItem(selected, onClick, icon, label) | 常用 | 底栏项 | 结构 |
AlertDialog(onDismissRequest, confirmButton, dismissButton, title, text) | 常用 | 对话框回调与文案 | 结构 |
ModalBottomSheet(onDismissRequest, sheetState) | 常用 | 半屏显隐 | 结构 |
SnackbarHostState.showSnackbar | 常用 | 弹出轻提示 | 结构 |
NavHost(navController, startDestination) | 常用 | 导航图入口 | 导航 |
navController.navigate / popBackStack | 常用 | 前进 / 返回 | 导航 |
popUpTo / launchSingleTop / restoreState | 常用 | 底栏切 Tab、登录清栈 | 导航 |
navArgument / 路由参数 | 常用 | 传 id 等 | 导航 |
previousBackStackEntry.savedStateHandle | 常用 | 返回传值 | 导航 |
navDeepLink | 偶尔 | URL / 推送打开页 | 导航 |
组件参数 · 布局作用域
| 参数 | 频率 | 作用 | 链接 |
Column/Row(verticalArrangement, horizontalArrangement) | 常用 | 主轴分布 | 布局 |
Column/Row(horizontalAlignment, verticalAlignment) | 常用 | 交叉轴对齐 | 布局 |
Arrangement.spacedBy | 常用 | 统一间距 | 布局 |
Modifier(几乎所有组件第一个可选参) | 常用 | 外观与行为入口 | Modifier |
组件参数 · 主题与动画
| 参数 | 频率 | 作用 | 链接 |
MaterialTheme.colorScheme / typography / shapes | 常用 | 读主题令牌 | 主题 |
isSystemInDarkTheme + 三态 ThemeMode | 常用 | 跟随系统 / 浅 / 深 | 主题 |
isAppearanceLightStatusBars | 常用 | 状态栏图标深浅 | 主题 |
stringResource / pluralStringResource / painterResource | 常用 | 读文案 / 复数 / 图 | 主题 |
minimumInteractiveComponentSize | 常用 | 最小 48.dp 热区 | 主题 |
contentDescription / semantics(mergeDescendants) | 常用 | 读屏名字 / 合并行 | 主题 |
dynamicLight/DarkColorScheme | 偶尔 | 壁纸取色 | 主题 |
animate*AsState(targetValue, animationSpec, label) | 常用 | 单值平滑过渡 | 动画 |
AnimatedVisibility(visible, enter, exit) | 常用 | 显隐动画 | 动画 |
fadeIn/Out · slideIn/Out* · expand/shrink* · scaleIn/Out | 常用 | 进出效果,可 + 叠加 | 动画 |
AnimatedContent(transitionSpec, togetherWith) | 常用 | 槽位换内容 | 动画 |
spring / tween / infiniteRepeatable | 常用 | 动画规格 | 动画 |
keyframes / repeatable / snap / exponentialDecay | 偶尔 | 关键帧 / 有限重复 / 吸附 / 甩动 | 动画 |
易错合集
- Modifier:先
background 后 padding ≠ 先 padding 后 background(谁包住谁)
- 点击:
clickable 与 padding 顺序决定热区大小
- 状态:
mutableStateOf 必须包 remember;输入框必须 value + onValueChange
- 列表:长列表用 Lazy;
key 别用 index;勿 verticalScroll 嵌套 Lazy
- Scaffold:内容记得吃
paddingValues,否则被顶底栏挡住
- Snackbar:挂
snackbarHost,别当普通 Text 随处弹
- 副作用:Composable 体里别直接发请求 → 见副作用
- 无障碍:装饰性 Icon/Image 的
contentDescription 传 null
- 动画:要进出用
AnimatedVisibility,不要用裸 if;目标值必须来自稳定 State
- 导航:底栏必须
popUpTo + launchSingleTop;不要在组合体里直接 navigate
- 列表:PullToRefresh 包在 Lazy 外;Paging 失败用 Error 不是空页;翻页靠滑动不是 refresh()
- 主题:业务页勿写死 hex;主色上的字用 onPrimary;设置深色要三态;装饰图 contentDescription 传 null