Google地图片段和AdMob,地图位置按钮位于广告下方

时间:2014-11-10 04:09:00

标签: android google-maps android-fragments admob mapfragment

您好我有一个布局,顶部有一个菜单栏,然后​​是地图片段,然后是AdMob横幅。除了某些原因,MapFragment中的“获取位置”按钮大部分隐藏在adMob横幅下方之外,它几乎都显示为所需。即使地图确实在横幅上方结束,也会剪切“获取位置”按钮。任何帮助将不胜感激AdFragment是AdMob横幅示例(包含AdView元素的RelativeLayout)的精确副本。这是我的布局看起来像,任何帮助将不胜感激。我还注意到,如果我用RelativeLayout替换adFragment,我的位置按钮不会被剪裁但是不合适,以适应地图屏幕

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mapScreen"
android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/layoutTop"
        android:layout_width="match_parent"
        android:layout_height="45dp">
    </RelativeLayout>
    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_height="0dp"
        android:layout_weight="1"/>
    <fragment
        android:id="@+id/adFragment"
        android:name="xxxx$AdFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>



</LinearLayout >

1 个答案:

答案 0 :(得分:4)

您的主要问题是您告诉map身高match_parent

我怀疑你的意图是map展开以填充layoutTopadFragment之间的空格。如果是这样,最好使用layout_weight="1" map的LinearLayout,如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mapScreen"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/layoutTop"
        android:layout_width="match_parent"
        android:layout_height="45dp">
    </RelativeLayout>

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
     />

    <fragment
        android:id="@+id/adFragment"
        android:name="xxxx$AdFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>