嗨,我正在尝试在Google地图上方显示一个按钮,有人可以告诉我在尝试不同的位置后,我的按钮会显示在地图后面吗?
到目前为止,这是我的代码:
<?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>
如果您通过在Java文件中尝试替代解决方案,可以在onCreate方法中尝试以下代码,这将在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);
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句