我第一次尝试在 Android 中显示 map 。
现在 我想在 map 上显示 3 个按钮,当我点击一个特定的按钮时,应该引发该按钮的点击事件。
map 应该是全屏的和按钮在下方。
我不知道我该怎么做?当我们想使用 MapView 显示 map 时,我们必须扩展 MapActivity 类。因此,请提出一些想法、示例或引用站点。
编辑:
我使用以下布局显示 map :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
android:id="@+id/mapView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:enabled="true"
android:clickable="true"
android:apiKey="my generated api key"
/>
<Button
android:text="Button"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
最佳答案
Praveen 的回答很好。请记住,RelativeLayout
的最大优点之一是您可以避免不必要的嵌套。布局越简单,维护起来就越容易。这等同于 Praveen 的回答:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mapview"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:clickable="true" android:apiKey="your_id" />
<Button android:layout_below="@+id/mapview"
android:text="@+id/Button03"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"/>
<Button android:layout_below="@+id/mapview"
android:text="@+id/Button02"
android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"/>
<Button android:text="@+id/Button03"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_toLeftOf="@+id/mapview"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
关于Android - 带有 3 个按钮的 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3544875/