Search code examples
androidandroid-mapviewgoogle-maps-mobile

Limiting the MapView to half the screen


I am trying to get the map to fill in only the upper half of the screen and some other layout in the bottom half. Now I know that this should be possible using weights in combination with a tablelayout. But the same piece of XML code works perfectly with say buttons but not with map.
Screenshots here.

The XML code:

<TableLayout
    android:id="@+id/tableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" 
        >
            <com.google.android.maps.MapView
            android:id="@+id/map2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:apiKey="0_z4IHjB6EnXohnoyoudontgoVmhg"
            android:clickable="true" >
        </com.google.android.maps.MapView>

    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" >
        <Button android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="SECOND"></Button>

    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" >
        <Button android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="SECOND"></Button>
    </TableRow>
</TableLayout>

If you replace the Mapview block by say a button, it will look like the first image in the screenshot, whereas right now it looks like the second one.
In both cases I did not change any weight parameters or layout_width or height, but it somehow changes the size. Any idea how can I have the MapView to cover only half the screen?


Solution

  • Sorry Urban, gave you a bum steer on it - I had looked at this before and the only way I could limit the map size was programmatically, however, I have since done it with this type of layout:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"     
     android:orientation="vertical" >          
    
     <FrameLayout android:id="@+id/map_frame"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_weight="0.7" >     
    
        <com.google.android.maps.MapView
            android:id="@+id/map_view" 
            android:layout_width="fill_parent"
            android:layout_height="match_parent" 
            android:enabled="true" 
            android:clickable="true"             
            android:apiKey="dgvbdj_my_secret_key_nvc8mxcksos"/>
    
     </FrameLayout>
    
     <co.uk.mycompany.ui.MapNavBar
        android:id="@+id/map_nav"
        android:layout_width="fill_parent"
        android:layout_height="70dip"
        android:layout_gravity="bottom"
        android:layout_weight="0.3" /> 
    

    The last item shown is a custom widget but the layout should show the principles involved. This limited the map height but allowed it to go full width.