android的layout在哪里,android:layout_below位置到底below到哪儿了?

android:layout_below是RelativeLayout的一个属性,其官方解释如下:

—Positions the top edge of this view below the given anchor view ID and must be a reference to another resource, in the form "@[+][package:]type:name"

我理解就是:将当前控件的顶部置于给定ID的控件之下,并且两控件应该对齐。然而事实证明我又傻傻的天真了T_T...

layout_blew.xml布局文件如下:

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/banner_text"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignWithParentIfMissing="true"

android:layout_marginBottom="3dp"

android:layout_marginRight="6dp"

android:includeFontPadding="false"

android:text="东航旗舰店"

android:visibility="visible"

android:textSize="15sp"/>

android:id="@+id/seat_space"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignBottom="@+id/banner_text"

android:layout_toRightOf="@+id/banner_text"

android:includeFontPadding="false"

android:textSize="13sp"

android:visibility="visible"

tools:text="经济舱"/>

android:id="@+id/airport_price_fee"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/seat_space"

android:includeFontPadding="false"

android:textSize="12sp"

tools:text="机建0"/>

布局的初衷是想在同一个RelativeLayout中将“机建”放在第二栏:

8c03d7391438

刚开始以“东航旗舰店”为参照,使用属性android:layout_below="@+id/banner_text",但由于“东航旗舰店”是动态显示的,有时候VISIBLE,有时候GONE(此时android:layout_below就找不到参照了,“机建”就会与第一栏重合),要实现正常显示就只能以“经济舱”为参照,使用android:layout_below="@+id/seat_space"。可是基于对android:layout_below属性的理解,用了觉得结果会是下面这样的(其实又添加了android:layout_alignLeft属性才是下面的效果):

8c03d7391438

结果试了才知道真心错了,android:layout_below="@+id/seat_space",只要控件seat_space(经济舱)不设为GONE,也无论“经济舱”位置在哪儿,"机建"都会在“经济舱”的下面一排的最左边(前提是“机建”没有设置其他对齐属性)。

8c03d7391438

总结:

android:layout_below属性会将当前控件的顶部置于给定ID的控件之下,但并不会与给定ID的控件对齐,默认会放在父控件的最左边;

可通过android:layout_alignLeft、android:layout_alignRight等对齐属性改变当前控件设置android:layout_below属性后的默认位置,RelativeLayout的具体其他属性点这里。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值