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>
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);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With