Show a button on Google Maps Android
•
Android
Hi, I want to display a button on Google maps. Someone can tell me how to do this because I tried different locations and my button is displayed at the back of the map
So far, this is my 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"
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>
resolvent:
If you try an alternative solution in a java file, try the following code in the oncreate method, which will create a button on Google maps
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);
}
});
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码