如何在 Compose 中排列 BottomNavigationItems?
我怎样才能安排两个内部BottomNav项目,使它们不那么靠近“+”FAB? 我尝试围绕 forEach 显示带有行的项目并使用排列修改器,如下所示:
Row(horizontalArrangement = Arrangement.SpaceBetween) { //Not working :(
items.forEach { item ->
BottomNavigationItem(
icon = { Icon(painterResource(id = item.icon), contentDescription = item.title) },
label = { Text(text = item.title) },
selectedContentColor = Color.White,
unselectedContentColor = Color.White.copy(0.4f),
alwaysShowLabel = true,
selected = currentRoute == item.route,
onClick = {
navController.navigate(item.route) {
navController.graph.startDestinationRoute?.let { route ->
popUpTo(route) {
saveState = true
}
}
launchSingleTop = true
restoreState = true
}
}
)
}
}
不幸的是,这不起作用
How can I arrange the two inner BottomNav Items so that they are not so close to the "+" FAB?
I tried surrounding the forEach which displays the Items with a Row and use the Arrangement modifier like so:
Row(horizontalArrangement = Arrangement.SpaceBetween) { //Not working :(
items.forEach { item ->
BottomNavigationItem(
icon = { Icon(painterResource(id = item.icon), contentDescription = item.title) },
label = { Text(text = item.title) },
selectedContentColor = Color.White,
unselectedContentColor = Color.White.copy(0.4f),
alwaysShowLabel = true,
selected = currentRoute == item.route,
onClick = {
navController.navigate(item.route) {
navController.graph.startDestinationRoute?.let { route ->
popUpTo(route) {
saveState = true
}
}
launchSingleTop = true
restoreState = true
}
}
)
}
}
Unfortunately thats not working
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Arrangement.SpaceBetween
按预期工作 - 它在项目之间添加了一个间隔:您需要让您的
Row
了解 FAB 位置。您可以在行中间添加带有Modifier.weight
的间隔符,例如如下所示:Arrangement.SpaceBetween
works as expected - it adds a spacer between items:You need to let your
Row
know about FAB location. You can add a spacer withModifier.weight
in the middle of your row, for example like this:您可以使用
BottomAppBar
&给它cutoutShape
并在中间添加一个虚拟项目。它会给你你想要的结果。输出:
代码示例:
You can use
BottomAppBar
& give itcutoutShape
with a dummy item in the middle. It would give you your desired results.Output:
Code Sample: