底部导航栏在添加超过3个元素后出现问题。

huangapple go评论68阅读模式
英文:

BottomNavbar breaks when you add more than 3 elements

问题

以下是翻译好的内容:

我正在开发一个安卓应用程序,最初计划在底部导航栏中只有3个片段。然而,项目范围已扩展,我们决定添加第四个片段。在添加第四个片段时,容器的尺寸发生了问题,呈现出以下的样子:

底部导航栏在添加超过3个元素后出现问题。

这是我的 XML 代码:

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    app:itemBackground="@color/colorPrimary"
    app:itemIconTint="@drawable/selector"
    app:itemTextColor="@drawable/selector"
    app:menu="@menu/menu_navigation" />

我尝试了不同的属性来使其伸展,但它们最终只能将其放置在右侧,而不能向左展开,反之亦然。例如,如果我尝试在 layout_width 上使用 wrap_content,容器将会贴靠在左侧。

可能是解决这个问题的所需属性是什么呢?

英文:

I am working on an android application and it was agreed to only have 3 fragments in its bottom navigation bar. However, things have expanded and we decided to add another fragment. When adding the 4th fragment, the dimensions of the container break making it look like this.

底部导航栏在添加超过3个元素后出现问题。

This is my xml code.

    &lt;com.google.android.material.bottomnavigation.BottomNavigationView
    android:id=&quot;@+id/bottom_navigation&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_alignParentBottom=&quot;true&quot;
    app:itemBackground=&quot;@color/colorPrimary&quot;
    app:itemIconTint=&quot;@drawable/selector&quot;
    app:itemTextColor=&quot;@drawable/selector&quot;
    app:menu=&quot;@menu/menu_navigation&quot; /&gt;

I have tried different properties to make it stretch but they end up putting it only to the right and not expanding left or vice versa. For instance if I was to try using wrap_content on the layout_width, the container would glue itself to the left.

What is the needed property that might be a solution to the problem?

答案1

得分: 0

这是一种自动措施,以防止标签重叠。
您可以通过在您的xml中添加 app:labelVisibilityMode="labeled" 来快速修复。

请注意,您应该使用支持库版本28进行此操作。

英文:

It's an automatic measure in order to not have labels overlap.
You can make a quick fix by adding app:labelVisibilityMode=&quot;labeled&quot; to your xml.

Note that you should use Use Support Library 28 for this.

huangapple
  • 本文由 发表于 2020年3月15日 20:23:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/60692827.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定