user721413
user721413

Reputation: 23

A android xml layout problem with google map

I want to build a layout like this:

enter image description here

My XML code:

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

But the result come out the total google map is put on top of every thing.
How can I fix this?

Upvotes: 2

Views: 6310

Answers (3)

Sunil Kumar Sahoo
Sunil Kumar Sahoo

Reputation: 53667

Use Relative Layout I have modified your code. Use the folowing code

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

Upvotes: 2

thaussma
thaussma

Reputation: 9886

The LinearLayout(linearLayout1) is out of the screen. You have to add the MapView and linearLayout1 in a 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>

Upvotes: 1

Walid Hossain
Walid Hossain

Reputation: 2714

Please use Relative layout instead of Linear Layout. If you don't know how to use relative layout please have a look on the following link http://developer.android.com/resources/tutorials/views/hello-relativelayout.html

Upvotes: 1

Related Questions