Как я могу добавить TextView ниже MapView?

Я следил за Hello Views, Google Map View и теперь хочу добавьте TextView под MapView. Я только изменил файл макета main.xml и поместил MapView и TextView по вертикали LinearLayout. Мой Eclipse настроен на автоматическую сборку, но когда я запускаю приложение в эмуляторе, я вижу только файл MapView.

Как добавить TextView под MapView?

Вот мой макет 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>

person Jonas    schedule 10.11.2010    source источник


Ответы (3)


Проблема в том, что вы используете android:layout_height="fill_parent" в своем MapView.

Я не понимаю, если ты хочешь:

  • TextView будет над картой
  • Уменьшите MapView, чтобы оставить место для TextView

В первом случае используйте <RelativeLayout> вместо <LinearLayout> и играйте с android:layout_alignParentBottom="true" вместо TextView.

Во втором случае используйте android:layout_weight. У меня не открыто затмение, но достаточно разместить android:layout_weight="1" в TextView.

person Macarse    schedule 10.11.2010
comment
Спасибо, я добавил вес как для MapView (1.0), так и для TextView (0.0), и теперь это работает. - person Jonas; 10.11.2010

Возможно, вы захотите попробовать RelativeLayout, например:

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

Я не мог заставить MapViews работать очень хорошо с LinearLayouts

person NickT    schedule 10.11.2010

Только сочетание

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

и

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

работал на меня.

person Andi R    schedule 27.03.2011