Android,获得4个线性布局

时间:2011-08-13 03:54:17

标签: android layout

我试图在屏幕上获得4个线性布局......但它只显示前两个:(
(我是菜鸟)这是我的代码:

<?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:id="@+id/linearLayout1" 
    android:background="@drawable/background">
    </LinearLayout>
    <LinearLayout android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/linearLayout2" 
    android:background="@drawable/background_ass">
    </LinearLayout>

 <LinearLayout android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/linearLayout3" 
    android:background="@drawable/background">
    </LinearLayout>

    <LinearLayout android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/linearLayout4" 
    android:background="@drawable/background_ass">
    </LinearLayout>

</LinearLayout>

2 个答案:

答案 0 :(得分:1)

您是否尝试在4个内部LinearLayouts上将layout_weight设置为“1”?可能是这样的:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">
    <LinearLayout android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:layout_weight="1"
                  android:background="#fafafa"/>
    <LinearLayout android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:layout_weight="1"
                  android:background="#000000"/>
    <LinearLayout android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:layout_weight="1"
                  android:background="#fafafa"/>
    <LinearLayout android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:layout_weight="1"
                  android:background="#000000"/>
</LinearLayout>

这应该共享布局之间的可用空间。

编辑提议的XML

答案 1 :(得分:0)

我认为这可能是因为您的前两个线性布局中可能显示的内容过多。因此前两个布局的wrap_content在屏幕上占用了太多空间。试着调查一下。

相关问题