问题
I have a simple layout as follows. Even though, I set all attributes as wrap_content, the resulting layout fills the entire screen height wise. The individual layouts in themselves are small. So the top level container should only be as big as to wrap all its elements. But it seems to fill the full screen. Width wise, the same attributes work fine. What am I missing here?
<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>
回答1:
It is the android:layout_alignParentBottom="true"
in your LinearLayout
that is causing the RelativeLayout
to stretch all the way to the bottom of the screen.
来源:https://stackoverflow.com/questions/4353840/what-does-relative-layout-wrap-content-do