代码之家  ›  专栏  ›  技术社区  ›  Jorpy

如何在Jetpack Compose中设置按钮高度和宽度?

  •  0
  • Jorpy  · 技术社区  · 11 月前

    如何在Jetpack Compose中设置按钮的高度和宽度?我无法设置按钮的高度和宽度。

    Button(onClick = {  },
           modifier =  Modifier.size(width = 80.dp,height = 80.dp)
            ) {
            Text(text = "Lorem")
        }
    

    按钮占据整个屏幕。 The button takes up the entire screen

    1 回复  |  直到 11 月前
        1
  •  0
  •   Vivek Modi    11 月前

    你必须使用 Column , Row 或任何其他布局。在此处阅读更多关于 Layouts .基本布局来自 here

    @Preview(showBackground = true)
    @Composable
    fun ButtonView() {
        Column(modifier = Modifier.fillMaxSize().background(Color.Yellow)) {
            Button(
                onClick = { },
                modifier = Modifier.size(width = 80.dp, height = 80.dp)
            ) {
                Text(text = "Lorem")
            }
        }
    }
    

    输出

    enter image description here