Проблема с макетом Android в Google Map - PullRequest
2 голосов
/ 30 июня 2011

Я хочу построить макет так:

enter image description here

Мой код XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/base">
<com.google.android.maps.MapView
    android:id = "@+id/mapView"
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:enabled="true"
    android:clickable="true"
    android:apiKey="0HD__0DaIgzDb8nHjJsuggkHlW1MofMwg-xVCpA"
    />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        </EditText>
<LinearLayout android:id="@+id/linearLayout1" 
    android:gravity="bottom"
    android:layout_width="fill_parent"
    android:orientation="horizontal" 
    android:layout_height="wrap_content"
    android:layout_weight="1">
    <Button android:text="Cancel" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"
    android:layout_weight="1" ></Button>
    <Button android:text="Confirm" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"
    android:layout_weight="1"  ></Button>
  </LinearLayout> 
 </LinearLayout>`

Но в результате получается, что общая карта Google находится на вершине каждой вещи.
Как я могу это исправить?

Ответы [ 3 ]

2 голосов
/ 30 июня 2011

Использовать Относительный макет Я изменил ваш код.Используйте следующий код

<?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"
    android:orientation="vertical"
    android:id="@+id/base">

    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:id="@+id/editText"
        >
    </EditText>
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:gravity="bottom"
        android:layout_width="fill_parent"
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_alignParentBottom="true">
        <Button
            android:text="Cancel"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_weight="1"></Button>
        <Button
            android:text="Confirm"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_weight="1"></Button>
    </LinearLayout>

    <com.google.android.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:enabled="true"
        android:clickable="true"
        android:apiKey="0HD__0DaIgzDb8nHjJsuggkHlW1MofMwg-xVCpA" 
        android:layout_below="@+id/editText"
        android:layout_above="@+id/linearLayout1"/>
</RelativeLayout>
1 голос
/ 30 июня 2011

LinearLayout (linearLayout1) находится вне экрана. Вы должны добавить MapView и linearLayout1 в FrameLayout:

    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:id="@+id/base">

        <FrameLayout  android:id ="@+id/framelayout"
            android:layout_width="match_parent" 
            android:layout_height="match_parent">

                   <com.google.android.maps.MapView
                      android:id = "@+id/mapView"
                       android:layout_width="match_parent" 
                       android:layout_height="match_parent"
                       android:enabled="true"
                       android:clickable="true"
                       android:apiKey="0HD__0DaIgzDb8nHjJsuggkHlW1MofMwg-xVCpA"
                       />
                       <EditText
                           android:layout_width="fill_parent"
                           android:layout_height="wrap_content">
                           </EditText>
                   <LinearLayout android:id="@+id/linearLayout1" 
                       android:gravity="bottom"
                       android:layout_width="fill_parent"
                       android:orientation="horizontal" 
                       android:layout_height="wrap_content"
                       android:layout_weight="1">
                       <Button android:text="Cancel" 
                       android:layout_height="wrap_content" 
                       android:layout_width="wrap_content"
                       android:layout_weight="1" ></Button>
                       <Button android:text="Confirm" 
                       android:layout_height="wrap_content" 
                       android:layout_width="wrap_content"
                       android:layout_weight="1"  ></Button>
                   </LinearLayout> 
        </FrameLayout>
     </LinearLayout>
1 голос
/ 30 июня 2011

Пожалуйста, используйте Относительный макет вместо линейного макета. Если вы не знаете, как использовать относительную компоновку, взгляните на следующую ссылку http://developer.android.com/resources/tutorials/views/hello-relativelayout.html

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...