Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display a button on top of Google maps Android

Hi I am trying to display a button on top of google maps, could someone please tell me how I could acheive this please as I have tried different positions and my button displays behind the map.

This is my code so far:

<?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"
android:orientation="vertical"
android:background="@color/BlanchedAlmond" >

<Button
    android:id="@+id/startActivityButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal|center_vertical"   
    android:onClick="startActivity"
    android:text="@string/start_activity" 
    android:layout_alignParentBottom="true"  />

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

</RelativeLayout>
like image 673
Natalie Carr Avatar asked Dec 02 '22 16:12

Natalie Carr


1 Answers

If you are giving a try to an alternate solution by doing it in java file you can try the code below in onCreate method ,this will create a button on top of google map

Button button = new Button(this);
button.setText("Click me");
addContentView(button, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

button.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent i=new Intent(this,SecondActivity.class);
                    startActivity(i);

                }
            });
like image 140
Auto-Droid ツ Avatar answered Dec 10 '22 13:12

Auto-Droid ツ