如何确定底部导航视图菜单项的位置? [英] How to fix the position of bottom navigation view menu items?

查看:107
本文介绍了如何确定底部导航视图菜单项的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主页中有一个底部导航视图,有四个菜单项.在onCreate()上,四个菜单项不在固定位置,仅在轻击标签并更改位置时才显示标签.我希望它们在标签可见的情况下保持固定的位置,而不是在触摸时改变位置.这是我的xml代码:

I have a bottom navigation view in my home page, there are four menu items. On onCreate(), the four menu items are not in fixed position, the label is shown only when it is tapped on and it changes the position. I want them to remain fixed in position with their labels visible, not changing position upon touching. Here are my xml codes:

     <?xml version="1.0" encoding="utf-8"?>
       <menu xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:app="http://schemas.android.com/apk/res-auto"
       xmlns:design="http://schemas.android.com/tools">
       <item
        android:id="@+id/menu_home"
        android:title="Home"
        android:enabled="true"
        android:icon="@drawable/home_icon"
        app:showAsAction="always"/>
    <item
        android:id="@+id/menu_wallet"
        android:title="Wallet"
        android:enabled="true"
        android:icon="@drawable/wallet_icon"
        app:showAsAction="always"/>

    <item
        android:id="@+id/menu_toto"
        android:title="Toto"
        android:enabled="true"
        android:icon="@drawable/toto_icon"
        app:showAsAction="always"/>
    <item
        android:id="@+id/menu_settings"
        android:title="Settings"
        android:enabled="true"
        android:icon="@drawable/setting_icon"
        app:showAsAction="always"/>
</menu>

和主要的xml是这样的:

and the main xml is like this:

<android.support.design.widget.BottomNavigationView
   android:id="@+id/navigation"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:layout_alignParentBottom="true"
   app:itemBackground="@color/homenavigationbottom"
   app:itemTextColor="@android:color/white"
   android:fitsSystemWindows="true"
   app:menu="@menu/bottom_navigation_menu"/>

推荐答案

在您的 activity_main.xml 文件代码中添加以下标记:

Add the following tag in your activity_main.xml file code:

android:layout_gravity="bottom"

更多信息: https://developer.android. com/reference/android/support/design/widget/BottomNavigationView.html

这篇关于如何确定底部导航视图菜单项的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆