【问题标题】:Why is my BottomBar in the middle of the screen?为什么我的 BottomBar 在屏幕中间?
【发布时间】:2017-01-18 16:08:43
【问题描述】:

我同时使用 NavigationDrawer 和 BottomNavigationView。但是添加导航抽屉后,底部导航的位置发生了变化。我该如何解决?我认为这个问题是由我的 xml 文件引起的。

activity_main.xml

<android.support.v4.widget.DrawerLayout  xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
tools:context="com.example.yunus.ototakip.MainActivity">

<include
    layout="@layout/app_bar_navigation_bar"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_navigation_bar"
    app:menu="@menu/activity_navigation_bar_drawer" />
<FrameLayout
    android:id="@+id/main_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true">
</FrameLayout>

<android.support.design.widget.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="@color/beyaz"
    app:itemTextColor="@color/beyaz"
    app:menu="@menu/bottombar_menu" />

【问题讨论】:

  • 您知道layout_alignParentBottom 是为RelativeLayout 服务的吗?
  • 啊,是的,但是我要如何在 DrawerLayout 的底部设置呢?

标签: android android-layout navigation-drawer bottombar


【解决方案1】:

将您的BottomNavigationView 附加到CoordinatorLayout(或您在app_bar_navigation_bar 布局中的任何视图组)而不是DrawerLayout 中,并添加适当的重力标签。

android:layout_gravity="bottom"

【讨论】:

    【解决方案2】:

    尝试使用两者中的任何一个=

    android:layout_gravity="bottom"
    

    android:gravity="bottom"
    

    【讨论】:

    • 我做到了。谢谢老兄。
    【解决方案3】:

    使用 android:layout_gravity="bottom" 而不是 layout_alignParentBottom,因为它用于 RelativeLayout 而不是 android.support.v4.widget.DrawerLayout。

    【讨论】:

    • 我收到此错误:索引 3 处的底部导航视图没有有效的 layout_gravity - 必须是 Gravity.LEFT、Gravity.RIGHT 或 Gravity.NO_GRAVITY
    猜你喜欢
    • 1970-01-01
    • 2022-09-28
    • 2022-11-23
    • 2022-10-18
    • 1970-01-01
    • 1970-01-01
    • 2015-05-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多