/ / Wie verhindere ich, dass TextView sein übergeordnetes LinearLayout ausstreckt? - Android, Textansicht, Android-Linearlayout

Wie verhindere ich, dass TextView sein übergeordnetes LinearLayout ausstreckt? - Android, Textansicht, Android-Linearlayout

Es scheint, dass ein TextView in einem LinearLayouterzwingt, dass LinearLayout größer wird. Ich versuche, meinen Bildschirm oben 50% und unten 50% zu teilen und auch die unteren 50% sind in 3 Teile aufgeteilt. Also habe ich meine Gewichte 3 (für die Spitze) und dann 1, 1, 1 (für die Unterseite) für insgesamt 6.

So sieht es aus. http://i.imgur.com/3FJSW.jpg

Sobald ich den TextView innerhalb derzuerst LinearLayout die Splits sind richtig. In dem Moment, in dem ich das TextView in das obere LinearLayout setze, wird das obere LinerLayout um den Betrag des TextView größer.

Hier ist mein 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>

Antworten:

1 für die Antwort № 1

Versuchen Sie, das Layout für die TextView zu ändern von:

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

Zu:

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

Wenn das nicht funktioniert, kann auch "Orientierung" entfernt werden.