什么是相对布局WRAP_CONTENT吗? [英] What does Relative layout wrap_content do?

查看:232
本文介绍了什么是相对布局WRAP_CONTENT吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的布局如下。虽然,我将所有的属性WRAP_CONTENT,得到的布局明智填满整个屏幕的高度。本身的各个布局小。所以顶层容器只应大如来包装其所有元素。但它似乎充满整个屏幕。宽明智的,相同的属性做工精细。
我缺少的是在这里吗?

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?

<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"
    />         

推荐答案

这是的android:layout_alignParentBottom =在真正的你的的LinearLayout 导致该 RelativeLayout的一路延伸到屏幕的底部。

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.

这篇关于什么是相对布局WRAP_CONTENT吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆