代码之家  ›  专栏  ›  技术社区  ›  Paresh Mayani jeet

Android-地图,带3个按钮

  •  2
  • Paresh Mayani jeet  · 技术社区  · 14 年前

    我第一次尝试在Android中显示地图。 现在 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. 地图应全屏显示,按钮位于下方。

    我不知道该怎么做?当我们想要使用mapview显示map时,我们必须扩展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>
    
    2 回复  |  直到 11 年前
        1
  •  5
  •   Cristian    14 年前

    普拉文的回答很好。请记住 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>
    
        2
  •  3
  •   Praveen    14 年前

    您需要的代码布局如下。

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