Android BottomNavigationView:图标和文本之间的空间太多
截至最近,底部的导航栏开始包括文本和图标之间的一些奇怪空间(我认为在更新依赖项之后):
现在,图标和文本之间似乎有一个间隔,它将两者都推到了栏的极端。到目前为止,我发现的只是使用app:itemPaddingTop
尝试手动将图标向下推回,但这会破坏较小的设备上的视图。
这是XML:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="?android:attr/windowBackground"
app:itemBackground="@color/darkGalaxy"
app:itemIconTint="@color/bottom_nav_color_selector"
app:itemTextColor="@color/bottom_nav_color_selector"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHeight_default="percent"
app:layout_constraintHeight_percent="0.1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />
是否有某种方法可以使它们都以最小的边距垂直居中?
As of recently the bottom nav bar started to include some strange space between the text and icons (I think after I updated the dependency):
(Colored red to see the boundaries)
There seems to be a spacer inbetween the icon and text now, which pushes both to the extreme ends of the bar. All I found so far is to use app:itemPaddingTop
to try and manually push the icons back down, but this breaks the view on smaller devices.
This is the xml:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="?android:attr/windowBackground"
app:itemBackground="@color/darkGalaxy"
app:itemIconTint="@color/bottom_nav_color_selector"
app:itemTextColor="@color/bottom_nav_color_selector"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHeight_default="percent"
app:layout_constraintHeight_percent="0.1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />
Is there some way to make them both centered vertically with minimal margin?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
测试后,我发现这是因为我使用
app:layout_constraintheight_percent =“ 0.1”
设置的自定义高度。伸展杠铃高于奇怪的是这样的内容(几个月前我第一次制作时,它都不像那样)。无论如何,我在那里只有此基于百分比的高度,因为使用
android:layout_height =“ wrap_content”底部的导航栏上的
使它占用了大部分屏幕。但是通过测试,我发现这仅是因为我使用android:background =“?android:attr/windowbackground”
。我不记得为什么使用它,但是将其删除使wrap_content
工作。After some testing, I found that it was because of the custom height that I set with
app:layout_constraintHeight_percent="0.1"
. Stretching the bar higher than it is weirdly spaces the content like this (it wasn't like that when I first made it some months ago).Anyway, I only had this percentage based height in there, because using
android:layout_height="wrap_content"
on the bottom nav bar made it take up most of the screen. But through the testing I found that this only happened because I was usingandroid:background="?android:attr/windowBackground"
. I cannot remember why I used it, but removing it makeswrap_content
work.经过一些调查后,看来
app:itemPaddingTop
和app:itempaddingBottom
属性可以帮助调整botes> botes> bottom> botes> botes> botes> botes> botes> botes> botes> botes> botes> botes> 。
实际上,他们只是在视图和图标的顶部边缘之间进行管理,然后分别在底部边缘和标签之间进行空间,但这也使您可以增加/减少图标和标签之间的空间。
After some investigation, it appears that
app:itemPaddingTop
andapp:itemPaddingBottom
attributes can help to adjust the space between the icon and label insideBottomNavigationView
item.Actually, they're just managing space between the top edge of the view and icon, and then the bottom edge and label respectively but that also makes it possible to increase/decrease space between icon and label.