Android中RelativeLayout布局各个xml相对布局属性的介绍和使用

在RelativeLayout类中的内部类LayoutParams提供了各种与相对布局有关的属性。

android:layout_above,android:layout_below,android:layout_toLeftOf,android:layout_toRightOf:分别用于控制此组件与其他组件的相对位置为上下左右。注意它不是表达此组件位于其他组件的正上边,正下边,正左边,正右边,它表达的是在垂直或者水平方向的上下紧邻或者左右紧邻。例如:(默认的组件都位于左上角)

  <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:layout_centerInParent="true"
        /><!--text1位于布局正中间-->
    <TextView
        android:id="@+id/text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/text1"
        android:text="example"
        />

结果:

android:layout_alignParentBottom,android:layout:alignParentTop,android:alignParentLeft,android:alignParentRight:这些属性都为布尔类型,设置此组件相对于父布局的对齐方式,意思是组件的下底上底左边右边与布局的相应四周重合,如果有布局矛盾,上述android:layout_above等四个属性有优先级(测试了一部分,不一定准确);

android:layout_alignBottom,android:layout:alignTop,android:alignLeft,android:alignRight:用于设置此组件与其他组件的对齐方式,与上面四种属性类似;

android:layout_centerHorizontal,android:layout_centerInParent,android:layout_centervertical:用于指定组件相对当前布局中的位置位于水平正中间,布局正中间,垂直方向正中间,是相对起始位置来说的水平垂直正中间。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值