Как я могу добавить 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>

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 должно быть достаточно.

Вы можете попробовать 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

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

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

а также

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

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

Другие вопросы по тегам