2010-11-10 5 views
2

J'ai suivi Hello Views, Google Map View et maintenant je veux ajouter un TextView sous le MapView. J'ai seulement changé le fichier de disposition main.xml et placé le MapView et le TextView dans un LinearLayout vertical. Mon Eclipse est configuré pour générer automatiquement ce code, mais lorsque j'exécute l'application dans l'émulateur, je ne vois que le MapView. Comment puis-je ajouter un TextView ci-dessous un MapView?Comment puis-je ajouter un TextView sous un MapView?

Voici ma mise en page 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> 

Répondre

5

Le problème que vous avez est que vous utilisez android:layout_height="fill_parent" dans votre MapView.

Je ne suis pas si vous voulez:

  • Le TextView d'être sur la carte
  • Réduire le MapView de laisser un espace pour le TextView

Dans le premier cas, utilisez un <RelativeLayout> au lieu d'un <LinearLayout> et jouer avec le android:layout_alignParentBottom="true" pour le TextView. Dans le second cas, utilisez android:layout_weight. Je n'ai pas d'éclipse ouverte mais placer android:layout_weight="1" au TextView devrait suffire.

+1

Merci, j'ai ajouté un poids à la fois sur 'MapView' (1.0) et sur' TextView' (0.0) et maintenant cela fonctionne. – Jonas

5

Vous pouvez essayer un RelativeLayout comme:

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

Je ne pouvais pas MapViews travailler très bien avec LinearLayouts

2

Seulement la combinaison de

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

et

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

a fonctionné pour moi.

Questions connexes