gpt4 book ai didi

android - 底部导航布局中谷歌地图 fragment 下的问题定位按钮

转载 作者:行者123 更新时间:2023-11-30 05:04:15 25 4
gpt4 key购买 nike

我有一个带有三个选项卡的底部导航的应用程序。在应用程序的屏幕之一上,我有一个 Google map fragment 。我希望仅在该屏幕的 map fragment 下方和底部导航上方显示三个按钮。

当我在这个特定 fragment 的设计器中时,它显示了我想要的东西(这里灰色的“fragment ”实际上是谷歌地图 fragment )

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

Designer view for the Google Map fragment

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

Runtime

我的目标是这个最终结果,(很抱歉对所需结果的解释不当,但你明白了!)

Desired result

这是 fragment 布局:

<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>

这是主要的 Activity 布局文件:

<?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>

我看起来要么无法在运行时正确操作 map fragment 高度,要么不能像在底部导航布局中那样使用它……或者我在某处犯了错误,这是极有可能的。

有什么线索吗?

最佳答案

如果我正确理解了您的查询,那么让我给您一个解决方案,您可以使用相对布局而不是如下所示的线性布局,并且让我告诉您,我知道您在主要 Activity 中也需要导航 View 您需要在导航 View 顶部的三个按钮,并且在其之上您需要 map fragment 。正确的?所以这是解决方案:

<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>

关于android - 底部导航布局中谷歌地图 fragment 下的问题定位按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54851552/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com