1

Hi I have a layout which has a menu bar at the top, then a map fragment and then an AdMob banner. It all displays almost as wanted, except for some reason the Get Location button in the MapFragment is mostly hidden underneath the adMob banner. Even though the map does end above the banner the Get Location button is clipped. Any help would be appreciated the AdFragment is an exact replica of the AdMob banner example (a RelativeLayout wrapped around an AdView element). Here is what my Layout looks like, any help would be appreciated. I have also noticed if i replace the adFragment with a RelativeLayout the My Location button isn't clipped but out of proportion to fit on the Map screen

<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 >
Profes
  • 93
  • 1
  • 9

1 Answers1

4

Your main problem is that you have told map to have a height of match_parent.

I suspect what you intended was to have map expand to fill the space between layoutTop and adFragment. If so you are better off using a LinearLayout with a layout_weight="1" for map, like so:

<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>
William
  • 20,150
  • 8
  • 49
  • 91
  • Unfortunately still the same result where the Get My Location button is clipped of the screen, in case this makes a difference I used android:layout_gravity="fill" andoird:weight="1" – Profes Nov 11 '14 at 02:50
  • Obviously I can't because it doesn't compile: layout_height requires a measurement unit e.g. "0dp" and layout_gravity does not accept integers. Furthermore without android:gravity on the fragment, it takes up a height of 0. Maybe i'm missing something here... Thanks – Profes Nov 11 '14 at 20:15
  • Sorry, see my edit. I meant layout_weight, not layout_gravity. And yes layout_height="0dp" – William Nov 11 '14 at 20:47
  • Sorry for the late response still the same result using the provided specifications, perhaps this is a bug with the android map fragment? – Profes Nov 27 '14 at 03:25
  • Make sure that your Map Fragment is wrapped in a LinearLayout. See edits above (the LinearLayout wasn't showing). layout_weight applies to a containing LinearLayout. – William Nov 27 '14 at 05:38
  • Thanks for your help William, turns out the reason it was being clipped was due to some code moving the Layout button in the background (The hazards of picking up someone else's messy code). Regardless I learn't some things about layouts, cheers. – Profes Dec 02 '14 at 21:55