Android - 带有 3 个按钮的 map

标签 android android-layout android-mapview android-button

我第一次尝试在 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/

相关文章:

android - Textview文字填满了屏幕吗?

Android:如何将RelativeLayout填充到屏幕的全宽?

android - 打开软键盘时是否有可能获得事件?

java - 无法在 "/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/jarsigner"找到可执行文件

android - HoloEverywhere,带有 Gradle 的 ActionBarSherlock 给出 'Attribute xxx has already been defined'

java - Android 按钮只能在角落点击

android - 使用 Dialog Fragment 膨胀 View

android - 在 MapView 上绘制透明

javascript - 直接在WebView或MapView中使用Google Maps JavaScript API?优点和缺点?

android - 在 Android 中绘制(过滤)100k+ 点到 MapView