2

I followed Hello Views, Google Map View and now I want to add a TextView under below the MapView. I have only changed the layout file main.xml and placed the MapView and the TextView in a vertical LinearLayout. My Eclipse is set to build this automatically, but when I run the application in the emulator, I can only see the MapView.

How can I add a TextView below a MapView?

Here is my layout main.xml:

<?xml version="1.0" encoding="utf-8"?>
<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/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
        android:apiKey="my key"
    />

    <TextView
        android:id="@+id/textview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="My TextView"
    />

</LinearLayout>
Jonas
  • 121,568
  • 97
  • 310
  • 388

3 Answers3

5

You might like to try a RelativeLayout like:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:id="@+id/MyTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello"
        android:layout_alignParentBottom="true" />
    <com.google.android.maps.MapView
        android:id="@+id/map"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:apiKey="Your api key"
        android:enabled="true"
        android:clickable="true"
        android:layout_above="@+id/MyTextView"" />
</RelativeLayout>

I couldn't get MapViews to work very well with LinearLayouts

NickT
  • 23,844
  • 11
  • 78
  • 121
5

The issue you have is that you are using android:layout_height="fill_parent" in your MapView.

I don't get if you want:

  • The TextView to be over the map
  • Shrink the MapView to leave space for the TextView

In the first case use a <RelativeLayout> instead of a <LinearLayout> and play with the android:layout_alignParentBottom="true" for the TextView.

In the second case, use android:layout_weight. I don't have eclipse opened but placing android:layout_weight="1"to the TextView should be enough.

Macarse
  • 91,829
  • 44
  • 175
  • 230
  • 1
    Thanks, I added a weight on both the `MapView` (1.0) and on the `TextView` (0.0) and now it works. – Jonas Nov 10 '10 at 12:09
2

Only the combination of

<TextView android:layout_alignParentBottom="true" ... />

and

<com.google.android.maps.MapView android:layout_above="@+id/MyTextView" ... />

worked for me.

Andi R
  • 21
  • 3