如何在每个 phone 上显示 bottomnavigationbar?

How can I show bottomnavigationbar on every phone?

我正在尝试将 bottomNavigationBar 与 google 地图一起实施。 但是 GoogleMaps 占用了所有剩余的 space 并覆盖了 bottomNavigatonBar。如果我用 "dp" 左右定义 googleMaps 高度,它只适用于一种屏幕尺寸。 有什么方法可以让 BottomNavigationView 与 googleMap 一起填充屏幕?

那是我实际的 xml 文件:

<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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".fahrplanmap">

<com.MultiSelectionSpinner
    android:id="@+id/mySpinner1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<Button
    android:id="@+id/getSelected"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Check"/>

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapsAnzeigeActivity" />

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="?android:attr/windowBackground"
    app:menu="@menu/navigation" />

</LinearLayout>

试试 RelativeLayout

像这样

<RelativeLayout 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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".fahrplanmap">

    <com.MultiSelectionSpinner
        android:id="@+id/mySpinner1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/getSelected"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/mySpinner1"
        android:text="Check" />

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/navigation"
        android:layout_below="@+id/getSelected"
        tools:context=".MapsAnzeigeActivity" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:layout_alignParentBottom="true"
        android:background="?android:attr/windowBackground"
        app:menu="@menu/navigation" />
</RelativeLayout>

这是它的样子

您可以尝试使用framelayout来解决这个问题 尝试这样的事情

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapsAnzeigeActivity" />

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="?android:attr/windowBackground"
    app:menu="@menu/navigation" />
</FrameLayout>