How can I add button on MapView android

Jovan picture Jovan · Aug 25, 2011 · Viewed 14.6k times · Source

As you can see from the question I need to put some button on mapView, where the app will by presing the button by user, refresh the mapView with current location. I know how to put the button above, under, but how to put on map??? If anyone has some sample code, or some guidance help is appreciated...

Answer

hooked82 picture hooked82 · Aug 25, 2011

You'll want to use a RelativeLayout and lay the button over top of the MapView. Just make sure not to place it over the Google logo. Here's a sample XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
    <com.google.android.maps.MapView android:id="@+id/google_maps"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="@string/maps_key"/>
    <Button android:id="@+id/googlemaps_select_location"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:text="Select"/>
</RelativeLayout>