Android - карта с 3 кнопками - PullRequest
2 голосов
/ 23 августа 2010

Я пытаюсь отобразить карту в 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, мы должны расширить класс 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 ]

5 голосов
/ 23 августа 2010

Правин ответил хорошо.Просто помните, что одним из величайших преимуществ RelativeLayout является то, что вы можете избежать ненужного вложения.Чем проще ваш макет, тем легче его поддерживать.Это эквивалентно ответу Правина:

<?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>
3 голосов
/ 23 августа 2010

требуемая раскладка кода ниже.

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