-
文本
方法:
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) ) { } }
-
列表
LazyColumn
LazyColumn { // 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") } }
-
横向列表
LazyRow
LazyRow(content = { item { Image(painterResource(R.drawable.xxx), "test") } item { Image(painterResource(R.drawable.xxx), "test") } })
Android Jetpack Compose控件基础篇
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 导引 本文原文在这里: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...