Android BottomNavigationView:图标和文本之间的空间太多

发布于 2025-01-29 01:41:45 字数 1361 浏览 4 评论 0原文

截至最近,底部的导航栏开始包括文本和图标之间的一些奇怪空间(我认为在更新依赖项之后):

“在此处输入映像”
(彩色红色以查看边界)

现在,图标和文本之间似乎有一个间隔,它将两者都推到了栏的极端。到目前为止,我发现的只是使用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):

enter image description here
(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?

Basically to look like this:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁许谁一生繁华 2025-02-05 01:41:45

测试后,我发现这是因为我使用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 using android:background="?android:attr/windowBackground". I cannot remember why I used it, but removing it makes wrap_content work.

荭秂 2025-02-05 01:41:45

经过一些调查后,看来app:itemPaddingTopapp:itempaddingBottom属性可以帮助调整botes> botes> bottom> botes> botes> botes> botes> botes> botes> botes> botes> botes> botes> 。

实际上,他们只是在视图和图标的顶部边缘之间进行管理,然后分别在底部边缘和标签之间进行空间,但这也使您可以增加/减少图标和标签之间的空间。

After some investigation, it appears that app:itemPaddingTop and app:itemPaddingBottom attributes can help to adjust the space between the icon and label inside BottomNavigationView 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文