首页 > 解决方案 > 使用 Jetpack Compose 连续绘制两个按钮

问题描述

我想在 a 中有两个按钮Row,就像在图片中一样,但是在我的代码中我设置了一个特定的 Horizo​​ntalArrangment,它在其他设备上看起来不太好

Row(
        horizontalArrangement = Arrangement.spacedBy(170.dp),
        modifier = Modifier.fillMaxWidth()
    ) {
        Button(
            onClick = { /*TODO*/ },
        ) {
            Text(
                modifier = Modifier.padding(8.dp),
                text = "Send Email",
                style = TextStyle(fontSize = 15.sp)
            )
        }
        Button(
            onClick = { /*TODO*/ },
        ) {
            Text(
                modifier = Modifier.padding(8.dp),
                text = "Call",
                style = TextStyle(fontSize = 15.sp)
            )
        }
    }

在此处输入图像描述

标签: androidandroid-buttonandroid-jetpack-compose

解决方案


您可以使用horizontalArrangement = Arrangement.SpaceBetween

就像是:

 Row(
        horizontalArrangement = Arrangement.SpaceBetween,
        modifier = Modifier.fillMaxWidth().padding(8.dp)
    ) {
        Button( onClick = { /*TODO*/ }){
            Text(
                text = "Send Email",
                style = TextStyle(fontSize = 15.sp)
            )
        }
        Button( onClick = { /*TODO*/ }) {
            Text(
                text = "Call",
                style = TextStyle(fontSize = 15.sp)
            )
        }
    }

![在此处输入图像描述


推荐阅读