android - 将 BottomNavigationView 放置在 CoordinatorLayout 中的布局下方

标签 android android-layout android-coordinatorlayout bottomnavigationview

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/coordinatorContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <!-- This coordinator Layout matches the parent's height, I want to height to match till the BottomNaviagtionView and not below it -->

    </android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/primaryDarkColor"
        app:itemIconTint="@color/primaryColor"
        android:layout_gravity="bottom"
        app:layout_scrollFlags="scroll|enterAlways|snap"
        app:itemTextColor="@color/primaryTextColor"
        app:menu="@menu/bottom_navigation_items"/>

</android.support.design.widget.CoordinatorLayout>

在此布局中,我在 CoordinatorLayout 中放置了一个 BottomNavigationView,其中还有另一个 CoordinatorLayout。问题是 BottomNavigationView 与内部协调器布局的底部重叠。因此需要建议使内部协调器布局 match_parent 直到 BottomNavigationView 并且不低于该值。

最佳答案

试试这个

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/coordinatorContent"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="match_parent">

        <!-- This coordinator Layout matches the parent's height, I want to height to match till the BottomNaviagtionView and not below it -->

    </android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/primaryDarkColor"
        app:itemIconTint="@color/primaryColor"
        android:layout_gravity="bottom"
        app:layout_scrollFlags="scroll|enterAlways|snap"
        app:itemTextColor="@color/primaryTextColor"
        app:menu="@menu/bottom_navigation_items"/>

</LinearLayout>

编辑

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <android.support.design.widget.CoordinatorLayout
            android:id="@+id/coordinatorContent"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="match_parent">


        </android.support.design.widget.CoordinatorLayout>

        <android.support.design.widget.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="#ff00"
            app:itemIconTint="#2639c9"
            android:layout_gravity="bottom"
            app:layout_scrollFlags="scroll|enterAlways|snap"
            app:itemTextColor="#0eec3b"
            app:menu="@menu/mymenu" />
    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>

关于android - 将 BottomNavigationView 放置在 CoordinatorLayout 中的布局下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50947658/

相关文章:

android - 如何在 android 中创建像 evernote 帮助这样的自定义 UI

android - 在 Android 布局底部添加工具栏时滚动行为不起作用

java - 无法解析 onBindViewHolder 中的符号 'textView'

android - 在不重新加载数据的情况下更新 viewpager 中的 fragment View

android - 是否可以将 Facebook 移动 SDK 仅用于移动应用安装广告?

android - 无法聚焦 EditText

android - 工具栏折叠时显示 View

android - NestedScrollView 内的 webview 导致高度问题

android - 如何通过公交获得覆盖距离

java - Android 线程错误 - 无法在未调用 Looper.prepare() 的线程内创建处理程序