What does Relative layout wrap_content do?

混江龙づ霸主 提交于 2019-12-14 01:13:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!