2012-04-09 4 views
1

Ich habe ein Problem beim Aufteilen des Bildschirms mit einem linearenLayout, Mein Ziel ist es in 9 Pisces - teilen Wenn ich begann mit dem LinearLayout zu spielen Ich bin zu dem folgenden Ergebnis gekommen:Probleme mit dem Aufteilen des Bildschirms mit LinearLayout

http://imageshack.us/photo/my-images/4/firstna.png/

mit dem folgenden xML-Code:

<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:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:baselineAligned="false"> 
    <FrameLayout 
     android:gravity="center_horizontal" 
     android:background="#aa0000" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_weight="1"> 
    </FrameLayout> 
    <FrameLayout 
     android:gravity="center_horizontal" 
     android:background="#00aa00" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_weight="4"/> 
    <FrameLayout 
     android:gravity="center_horizontal" 
     android:background="#aaaa00" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_weight="1"/> 
    </LinearLayout> 
    </LinearLayout> 

später, als ich versuchte Inhalt nach links hinzuzufügen FrameLayout es die Ratte geändert io dieser FrameLayout (was das Problem ist, ..):

http://imageshack.us/photo/my-images/692/secondp.png/

mit dem folgenden Code:

<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:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:baselineAligned="false"> 
    <FrameLayout 
     android:gravity="center_horizontal" 
     android:background="#aa0000" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_weight="1"> 
     <LinearLayout 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_weight="1"> 
<TextView 
    android:text="row one" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"/> 
<TextView 
    android:text="row two" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"/> 
<TextView 
    android:text="row three" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"/> 
<TextView 
    android:text="row four" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"/> 
    </LinearLayout> 
    </FrameLayout> 
    <FrameLayout 
     android:gravity="center_horizontal" 
     android:background="#00aa00" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_weight="4"/> 
    <FrameLayout 
     android:gravity="center_horizontal" 
     android:background="#aaaa00" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_weight="1"/> 
    </LinearLayout> 
    </LinearLayout> 

Ich möchte die Möglichkeit haben, die Layouts nur mit dem layout_weight Attribut zu steuern - Wenn das Hinzufügen von Inhalt zu FrameLayout sein Verhältnis ändert, würde ich Ihre Hilfe benötigen, um einen anderen Container zu finden, in dem das Verhältnis gespeichert wird. Danke.

Antwort

0

Wow, Sie verwenden viele verschachtelte Layouts! Muss Ihr linkes Layout ein Rahmenlayout mit einem anderen linearen Layout darin sein und dann alle Textansichten? Oder können Sie einfach das FrameLayout-Elternelement ersetzen und die Hintergrundfarbe in das vertikale LinearLayout verschieben?

Eigentlich dazu, warum brauchen Sie auch das 2. lineare Layout? Sie können einfach angeben, dass das erste lineare Layout horizontal ausgerichtet ist (Sie haben sowieso fill_parent auf der Höhe) und dann das zweite verschachtelte lineare Layout löschen.

Sie sollten wahrscheinlich auch die Layoutbreite der FrameLayouts auf 0dp ändern, so dass sie basierend auf dem Gewicht dynamisch skaliert werden.

Verwandte Themen