-
文本
方法:
Text()Text("默认") Text("大小、颜色", fontSize = 16.sp, color = Color.Blue) Text("斜体", fontStyle = FontStyle.Italic) Text("粗体", fontWeight = FontWeight.Bold) Text( "居中", textAlign = TextAlign.Center, modifier = Modifier.fillMaxWidth() ) Text("最大行数 ".repeat(50), maxLines = 2) Text("文字溢出 ".repeat(50), maxLines = 2, overflow = TextOverflow.Ellipsis) Text("字体1", fontFamily = FontFamily.Serif) Text("字体2", fontFamily = FontFamily.SansSerif)文字可选择:
SelectionContainer(){}文字不可选择:
DisableSelection(){}可点击文字:
ClickableText(){}组合文字:
buildAnnotatedString(){}Text( buildAnnotatedString { withStyle(style = SpanStyle(color = Color.Blue)) { append("H") } append("ello ") withStyle(style = SpanStyle(fontWeight = FontWeight.Bold, color = Color.Red)) { append("W") } append("orld") } ) -
图片
方法:
Image()/Icon()。两者没太大区别Image(painterResource(R.drawable.xxx), "image") Icon(painterResource(R.drawable.xxx), "icon") -
纵向布局
Column使用
Column可将多个项垂直地放置在屏幕上Column { Text("1") Text("2") } -
横向布局
Row
使用Row可将多个项水平地放置在屏幕上Row { Text("1") Text("2") } -
Box
使用Box可将一个元素放在另一个元素上Box { Box( Modifier .size(100.dp, 100.dp) .background(Color.Black) ) { } Box( Modifier .size(50.dp, 50.dp) .background(Color.Red) ) { } } -
列表
LazyColumnLazyColumn { // Add a single item item { Text(text = "First item") } // Add 5 items items(5) { index -> Text(text = "Item: $index") } // Add another single item item { Text(text = "Last item") } } -
横向列表
LazyRowLazyRow(content = { item { Image(painterResource(R.drawable.xxx), "test") } item { Image(painterResource(R.drawable.xxx), "test") } })
Android Jetpack Compose控件基础篇
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- 导引 本文原文在这里:Flutter for Android developers本文属于半翻译半笔记注解,按照自...
- http://www.cnblogs.com/Sweet-Candy/p/5695389.html React-N...
- 1 IOS组件 1.1 iOS活动指示器 1.1.1 Props animatingbool型 显示指示器(tru...