Anonymous
Выравнивание кнопок Jetpack Compose
Сообщение
Anonymous » 14 окт 2024, 12:37
Я пишу интерфейс на Kotlin, используя Jetpack Compose. Я только учусь и возникла проблема с расположением кнопок.
Хочу сделать так, чтобы кнопки "Проверить" и "Удалить" располагались сразу после поля ввода. Посмотрите на скриншоты, как это выглядит сейчас и как я пытаюсь это сделать.
Код:
Код: Выделить всё
Row(
Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(text = "Players", style = Typography.titleLarge)
IconButton(onClick = { isNewPlayer = true }) {
Icon(imageVector = Icons.Default.Add, contentDescription = "")
}
}
if (isNewPlayer) {
EditTextFieldSmall(
label = "New Player",
value = newPlayer.toStringWithEmpty(),
onValueChange = { newPlayer = it.toIntWithEmpty() }
)
IconButton(
onClick = {
val newList = club.player.toMutableList()
newList.add(newPlayer)
club = club.copy(player = newList)
newPlayer = 0
isNewPlayer = false
}
) {
Icon(
imageVector = Icons.Default.Check,
contentDescription = "",
tint = Color.Green,
modifier = Modifier.size(16.dp)
)
}
IconButton(
onClick = {
newPlayer = 0
isNewPlayer = false
}
) {
Icon(
imageVector = Icons.Default.Delete,
contentDescription = "",
tint = Color.Red,
modifier = Modifier.size(16.dp)
)
}
}
for (i in club.player.indices) {
EditTextFieldSmall(
label = "Player",
value = club.player[i].toStringWithEmpty(),
onValueChange = {
val newList = club.player.toMutableList()
newList[i] = it.toIntWithEmpty()
club = club.copy(player = newList)
}
)
IconButton(
onClick = {
val newList = club.player.toMutableList()
newList.removeAt(i)
club = club.copy(player = newList)
}
) {
Icon(
imageVector = Icons.Default.Delete,
contentDescription = "",
tint = Color.Red,
modifier = Modifier.size(16.dp)
)
}
}
И:
Код: Выделить всё
@Composable
fun EditTextFieldSmall(label: String, value: String, onValueChange: (String) -> Unit) {
Row(Modifier.fillMaxWidth().padding(top = 4.dp)) {
Text(text = label, color = Color.White)
Spacer(modifier = Modifier.width(8.dp))
BasicTextField(
modifier =
Modifier.width(130.dp)
.height(24.dp)
.background(EditTextFieldBackground, shapes.extraSmall),
value = value,
onValueChange = { newValue ->
if (newValue.length
Подробнее здесь: [url]https://stackoverflow.com/questions/79085592/jetpack-compose-button-alignment[/url]
1728898639
Anonymous
Я пишу интерфейс на Kotlin, используя Jetpack Compose. Я только учусь и возникла проблема с расположением кнопок. Хочу сделать так, чтобы кнопки "Проверить" и "Удалить" располагались сразу после поля ввода. Посмотрите на скриншоты, как это выглядит сейчас и как я пытаюсь это сделать. Код: [code] Row( Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween ) { Text(text = "Players", style = Typography.titleLarge) IconButton(onClick = { isNewPlayer = true }) { Icon(imageVector = Icons.Default.Add, contentDescription = "") } } if (isNewPlayer) { EditTextFieldSmall( label = "New Player", value = newPlayer.toStringWithEmpty(), onValueChange = { newPlayer = it.toIntWithEmpty() } ) IconButton( onClick = { val newList = club.player.toMutableList() newList.add(newPlayer) club = club.copy(player = newList) newPlayer = 0 isNewPlayer = false } ) { Icon( imageVector = Icons.Default.Check, contentDescription = "", tint = Color.Green, modifier = Modifier.size(16.dp) ) } IconButton( onClick = { newPlayer = 0 isNewPlayer = false } ) { Icon( imageVector = Icons.Default.Delete, contentDescription = "", tint = Color.Red, modifier = Modifier.size(16.dp) ) } } for (i in club.player.indices) { EditTextFieldSmall( label = "Player", value = club.player[i].toStringWithEmpty(), onValueChange = { val newList = club.player.toMutableList() newList[i] = it.toIntWithEmpty() club = club.copy(player = newList) } ) IconButton( onClick = { val newList = club.player.toMutableList() newList.removeAt(i) club = club.copy(player = newList) } ) { Icon( imageVector = Icons.Default.Delete, contentDescription = "", tint = Color.Red, modifier = Modifier.size(16.dp) ) } } [/code] И: [code] @Composable fun EditTextFieldSmall(label: String, value: String, onValueChange: (String) -> Unit) { Row(Modifier.fillMaxWidth().padding(top = 4.dp)) { Text(text = label, color = Color.White) Spacer(modifier = Modifier.width(8.dp)) BasicTextField( modifier = Modifier.width(130.dp) .height(24.dp) .background(EditTextFieldBackground, shapes.extraSmall), value = value, onValueChange = { newValue -> if (newValue.length Подробнее здесь: [url]https://stackoverflow.com/questions/79085592/jetpack-compose-button-alignment[/url]