0

I'm trying to constrain the size of a MapView so that it takes up, say 90% of the screen's height and leaves the remaining 10% at the bottom for another view e.g. a menu bar. I can get the effect but the menu bar overlays the MapView so that the bottom part of the map is not visible. Although the MapView can scroll the Google logo is partly obscured (and I suspect this might be against the T & C's of the Maps API), I'd rather constrain the MapView to be contained within a designated part of the screen. So far I haven't found any layout which enforces the MapView to the normal layout constraints e.g. layout_weight.

I'm beginning to think that this can only be achieved programatically by getting the device's screen dimensions and then explicitly setting the MapView layout width and height or has anyone managed to do this with an xml layout.

John J Smith
  • 11,435
  • 9
  • 53
  • 72
  • You are correct in that obscuring the Google logo is against the T&C's. Also I do not believe you can make the Google Maps view anything but full screen. – Austyn Mahoney Jun 08 '11 at 22:37
  • I have a view custom from mapview, and i can set layout_width, height, and weight normally. – xtr Jun 09 '11 at 03:42
  • I found it is possible to constrain the MapView size by putting layout_weights on its parent layout container. – John J Smith Aug 21 '11 at 18:49

1 Answers1

1

I found the answer here. It is basically what John said, use layout_weight:

<LinearLayout ... >
 <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="api_key"/>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />
 </FrameLayout>
</LinearLayout>

And the result

Community
  • 1
  • 1
Eduardo
  • 4,282
  • 2
  • 49
  • 63