我有一个带有三个标签的底部导航的应用程序。在应用程序的屏幕之一上,我有一个Google Map片段。我希望仅在此屏幕的地图片段下方和底部导航上方显示三个按钮。

当我在设计器中查看此特定片段时,它会显示我想要的内容(此处的灰色“片段”实际上就是Google Map片段)

您可以从github下载代码:https://github.com/guyprovost/BottomBug/tree/master

android - 在底部导航布局中的Google map 片段下定位按钮时出现问题-LMLPHP

但是,当我运行该应用程序时,这就是我得到的:

android - 在底部导航布局中的Google map 片段下定位按钮时出现问题-LMLPHP

我的目标是达到这个最终结果(很抱歉,对所需结果的解释很差,但是您明白了!)

android - 在底部导航布局中的Google map 片段下定位按钮时出现问题-LMLPHP

这是片段布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    class="com.google.android.gms.maps.MapFragment"
    android:layout_marginTop="24dp" />
<LinearLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/controlBar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="@color/primaryDark"
    android:gravity="bottom">
    <Button
        android:id="@+id/testbutton1"
        android:text="One"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_weight=".30"/>
    <Button
        android:id="@+id/testbutton2"
        android:text="Two"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_weight=".40" />
    <Button
        android:id="@+id/testbutton3"
        android:text="Three"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_weight=".30" />
</LinearLayout>




这是主要的活动布局文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottom_navigation" />
    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:layout_gravity="start"
        android:layout_alignParentBottom="true"
        android:background="@android:color/white"
        app:elevation="16dp"
        app:menu="@menu/bottom_navigation_main" />
</RelativeLayout>


这是底部导航菜单xml文件的内容:

    <?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">
    <item
        android:id="@+id/menu_map"
        android:enabled="true"
        android:icon="@drawable/ic_map"
        android:title="@string/tab1_title"
        app:showAsAction="ifRoom" />

    <item
        android:id="@+id/menu_history"
        android:enabled="true"
        android:icon="@drawable/ic_history"
        android:title="@string/tab2_title"
        app:showAsAction="ifRoom" />

    <item
        android:id="@+id/menu_settings"
        android:enabled="true"
        android:icon="@drawable/ic_settings"
        android:title="@string/tab3_title"
        app:showAsAction="ifRoom" />
</menu>


我看起来要么无法在运行时正确地操作地图碎片的高度,要么无法在底部导航布局中使用地图碎片的高度……或者我在某个地方惨遭杀害,这很可能发生。

有什么线索吗?

最佳答案

如果我正确理解了您的查询,那么让我给您一个解决方案,您可以使用相对布局而不是如下所示的线性布局,还让我告诉您,我了解您需要在主要活动中使用导航视图,并且还需要三个导航视图顶部和顶部的按钮需要地图片段。对?所以这是解决方案:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_above="@+id/controlBar"
        class="com.google.android.gms.maps.MapFragment"
        android:layout_marginTop="24dp" />
    <LinearLayout
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/controlBar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:background="@color/primaryDark"
        android:gravity="bottom">
        <Button
            android:id="@+id/testbutton1"
            android:text="One"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:layout_weight=".30"/>
        <Button
            android:id="@+id/testbutton2"
            android:text="Two"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:layout_weight=".40" />
        <Button
            android:id="@+id/testbutton3"
            android:text="Three"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:layout_weight=".30" />
    </LinearLayout>

07-27 17:14