4

我有一个简单的布局如下。尽管我将所有属性都设置为 wrap_content,但生成的布局会明智地填充整个屏幕高度。单独的布局本身很小。所以顶级容器应该只与包装其所有元素一样大。但它似乎填满了整个屏幕。宽度方面,相同的属性可以正常工作。我在这里想念什么?

<RelativeLayout 
    android:id="@+id/topcontainer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/solid_red"
>

<LinearLayout
    android:id="@+id/lowercontainer"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="10dip"
    android:layout_centerHorizontal="true"
    android:paddingLeft="0dip"
    android:paddingRight="0dip"
    android:layout_alignParentBottom="true"
    android:background="@drawable/solid_blue"
>

<ImageView
     android:id="@+id/lefticon"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" 
     android:background="@drawable/ic_settings_display"
     android:layout_alignParentLeft="true"
     android:layout_alignParentBottom="true"
     android:paddingRight="0dip"
/> 

<ImageView
     android:id="@+id/righticon"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" 
     android:background="@drawable/ic_settings_display"
     android:layout_alignParentRight="true"
     android:layout_alignParentBottom="true"
     android:paddingLeft="0dip"
/> 

</LinearLayout>

   <TextView android:id="@+id/test"
        android:text="Test text"
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:paddingTop="10dip"
        android:gravity="center"
        android:layout_centerHorizontal="true"
        android:textSize="20dip"
        android:layout_above="@id/lowercontainer"
        android:background="@drawable/solid_green"
   />         

</RelativeLayout>

替代文字

4

1 回答 1

5

正是android:layout_alignParentBottom="true"LinearLayout的内部导致RelativeLayout一直延伸到屏幕底部。

于 2010-12-04T13:59:16.483 回答