tags:

views:

58

answers:

2

Hello all,

I am basically 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 the particular button, the button's click event should be raised. (Map should be in full-screen and buttons are at below side)

I dont know, how do i do it ? becoz when we want to display map using mapview, at that time we have to extends MapActivity to the class. so please suggest me idea, example or referring site.

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>

Thanx

+1  A: 

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>
Praveen Chandrasekaran
@Praveen thanx for the answer
PM - Paresh Mayani
@Praveen Error in your layout code -> Button01 and Button03 having the same "id"
PM - Paresh Mayani
@Paresh Mayani: Sorry for that. but the layout design achieve what do you want. and Cristion write a most simplified code. it should works. ;)
Praveen Chandrasekaran
@Paresh thats gr8 and thanx for such support...i cant upvote more than once otherwise sure do it
PM - Paresh Mayani
+1  A: 

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>
Cristian
@Cristian you are right and thanx for the answer...Let me try it
PM - Paresh Mayani