在Compose中,如果需要设置控件的布局参数,需要设置控件modifier属性。
一、设置控件的宽高
1.设置宽度铺满全屏:modifier = Modifier.fillMaxWidth();
2.设置高度铺满全屏:modifier = Modifier.fillMaxHeight();
3.设置宽高铺满全屏:modifier = Modifier.fillMaxWidth().fillMaxHeight()
或modifier = Modifier.fillMaxSize()
二、设置控件的背景
1.单纯设置控件背景颜色可以使用 modifier = Modifier.background(Color.Blue))
2.如果要设置背景颜色之外,可以使用
modifier = Modifier.background(Color.Blue, RectangleShape));// 蓝色矩形
modifier = Modifier.background(Color.Blue, CircleShape));// 蓝色圆形
// 蓝色背景,左上10dp,右上20dp,左下10dp,右下20dp // RoundedCornerShape如果传一个参数就是4个圆角的值 modifier = Modifier.background(Color.Blue,RoundedCornerShape(10.dp,20.dp,10.dp,20.dp)))
// 水平渐变
val colors = listOf(Color.Blue, Color.Red)
modifier = Modifier.