【发布时间】:2019-02-24 11:46:08
【问题描述】:
我有一个带有三个标签的底部导航应用。在应用程序的一个屏幕上,我有一个谷歌地图片段。我希望仅在此屏幕的地图片段下方和底部导航上方显示三个按钮。
当我在这个特定片段的设计器中时,它显示了我想要的(这里灰色的“片段”实际上是谷歌地图片段)
你可以从github下载代码:https://github.com/guyprovost/BottomBug/tree/master
但是当我运行应用程序时,我得到了:
我的目标是这个最终结果,(很抱歉对预期结果的解释不佳,但你明白了!)
这是片段布局:
<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>
我看起来要么无法在运行时正确操作地图片段高度,要么不能像在底部导航布局中那样使用它......或者我在某个地方搞砸了,这很有可能。
有什么线索吗?
【问题讨论】:
-
尝试通过代码而不是xml管理MapFragment
-
我不确定我是否理解您的提示,但渴望学习...
-
可能的错误是您在片段的布局中使用了权重,但没有相应地为
LinearLayout分配权重。这样做,请使用match_parent而不是fill_parent -
在主要活动布局中尝试为框架布局提供 56dp 底部边距。
-
试着把这条线放在你的bottomNavigationXml中:
android:background="@android:color/transparent"它会让你的底部导航透明,你可以看到你的三个按钮是否真的在底部导航后面。
标签: android android-layout android-fragments xamarin.android