开发者

Android - map with 3 buttons

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 cl开发者_如何学Goick 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>


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>


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜