2012-04-09 106 views
1

我在使用linearLayout分割屏幕時遇到問題,我的目標是將其分割爲9個雙魚座 - 當我開始玩LinearLayout時,我得到以下結果:使用LinearLayout分割屏幕的問題

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

與下面的XML代碼:

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

後來當我試圖將內容添加到左邊的FrameLayout它改變了老鼠這個FrameLayout裏的IO(這是問題。):

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

使用下面的代碼:

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

我想有控制佈局剛好與layout_weight屬性的能力 - 如果向FrameLayout添加內容更改其比例,我需要您的幫助來查找另一個容器,該比率將保存在其中。 謝謝。

回答

0

哇你使用了很多嵌套的佈局!您的左手佈局是否需要在其內部使用另一個線性佈局,然後是所有文字查看?或者你可以只替換FrameLayout父項並將背景顏色移動到垂直LinearLayout?

實際上,爲什麼還需要第二個線性佈局呢?您可以指定第一個線性佈局的水平方向(無論如何您都有fill_parent),然後刪除第二個嵌套的線性佈局。

另外,您應該考慮將FrameLayouts的佈局寬度更改爲0dp,以便根據重量動態調整大小。