2012-04-09 57 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,以便根据重量动态调整大小。