2010-07-24 6 views
1

Il semble qu'un TextView à l'intérieur d'un LinearLayout force LinearLayout à être plus grand. J'essaie de diviser mon écran 50% et le fond 50% et les 50% inférieurs sont divisés en 3 parties. Donc j'ai fait mes poids 3 (pour le haut), puis 1, 1, 1 (pour le fond) pour un total de 6.Comment empêcher TextView d'étirer son parent LinearLayout?

Voici à quoi ça ressemble. Dès que je sors le TextView à l'intérieur du premier LinearLayout, les divisions sont correctes. Au moment où je place le TextView dans le LinearLayout supérieur, le LinerLayout supérieur grossit de la quantité de TextView.

Voici mon code:

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

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:background="#cccccc" 
    android:layout_weight="3"> 
     <TextView 
     android:text="@string/hello" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="#000000" 
     android:layout_weight="1"/> 
</LinearLayout>  

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:background="#aa0000" 
    android:layout_weight="1"> 
</LinearLayout>  

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:background="#00aa00" 
    android:layout_weight="1"> 
</LinearLayout>  

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:background="#0000cc" 
    android:layout_weight="1"> 
</LinearLayout></LinearLayout> 
+0

Je pense qu'avec votre poids de 1 sur le textview, vous forcez la linearlayout à être 3 fois la taille de la hauteur du textview. essayez de supprimer le poids du texte. – Sephy

Répondre

1

Essayez de changer la mise en page pour la TextView de:

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:background="#cccccc" 
    android:layout_weight="3"> 

Pour:

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:background="#cccccc" 
    android:layout_weight="1"> 

Si cela ne fonctionne pas, peut-être prendre de suite " orientation "aussi bien.

Questions connexes