Android - 带 3 个按钮的地图

发布于 2024-09-15 17:04:40 字数 963 浏览 5 评论 0原文

我第一次尝试在 Android 中显示地图。 现在我想在地图上显示3个按钮,当我单击特定按钮时,应该引发该按钮的单击事件。地图应该是全屏的按钮位于下方。

我不知道我该怎么做?当我们想要使用 MapView 显示地图时,我们必须扩展 MapActivity 类。因此,请提出一些想法、示例或参考站点。

编辑:

我已使用以下布局显示地图:

<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>

I am trying to display map in Android for the first time.
Now I want to display 3 buttons on the map, and when I clicked on a particular button, that button's click event should be raised. The map should be in full-screen and buttons are at the below side.

I don't know how I do this? When we want to display map using a MapView we have to extends the MapActivity class. So please suggest some ideas, examples or reference sites.

Edited:

I have displayed map using the following Layout:

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱你不解释 2024-09-22 17:04:40

普拉文的回答很好。请记住,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>

Praveen's answer is fine. Just keep in mind that one of the greatest avantages of RelativeLayout is that you can avoid unnecessary nesting. The more simple your layout, the easier to maintain it is. This is equivalent to Praveen's answer:

<?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>
毁我热情 2024-09-22 17:04:40

您需要的代码布局如下。

<?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" />


    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
        <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"></Button>
        <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_centerInParent="true"></Button>
        <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"></Button>
    </RelativeLayout>





</RelativeLayout>

the code layout that you need is below.

<?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" />


    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
        <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"></Button>
        <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_centerInParent="true"></Button>
        <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"></Button>
    </RelativeLayout>





</RelativeLayout>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文