3

I am new to android. I am doing a project as part of my academic. I would like to have few buttons in bottom of the Google Map android like in the waze android application(Sorry that not able to post screen shot). I have tried few things based on the below link How to add buttons at top of map fragment API v2 layout . But did not get desired results.

Can someone please help me with the proper layout. Appreciate your help.

Community
  • 1
  • 1
Vinoth Sivakumar
  • 55
  • 1
  • 2
  • 9

3 Answers3

4

Try this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.MapFragment" />

    <Button
        android:id="@+id/setRangeButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/setRange" />
</RelativeLayout>
markubik
  • 646
  • 4
  • 9
2

You can extends SupportMapFragment and override OnCreateView to do it programatically::

public class myMap extends SupportMapFragment{ 

    private Context context; 

    public View onCreateView(LayoutInflater inflater,
            @Nullable ViewGroup container,
            @Nullable Bundle savedInstanceState) {
        // TODO Auto-generated method stub  

        View v = super.onCreateView(inflater, container,savedInstanceState);  

        //save context
        this.context = v.getContext();

        RelativeLayout view = new RelativeLayout(v.getContext());  


       //add relative layout
        view.addView(v, new RelativeLayout.LayoutParams(-1, -1));  

        TextView stuff = new EditText(v.getContext());
        stuff.setText("Hey you, I was added programatically!");


        view.addView(stuff);


        initializeMap();
        return view;  //return 
    }

    private initializeMap(){
        //add things to the map here  
        getMap().addMarker(new MarkerOptions().add(new LatLng(-37.81319, 144.96298))); 
    }
}
jeprubio
  • 17,312
  • 5
  • 45
  • 56
dinsomniac
  • 56
  • 2
0

Use this code

<?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" >

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <Button 
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="Button 1"/>


</RelativeLayout>
Krunal Shah
  • 1,438
  • 1
  • 17
  • 29