相对布局(中)

主要内容:

1   对齐至控件的基准线  
2   与父控件的四个边缘对齐  
3   对齐至父控件的中央

什么是基准线(baseline)  
基准线:为了保证印刷字母的整齐而划定的线  


如上图所示,从上到下的第3条线就为基准线。

那么如何对齐呢?

android:layout_alignBaseline="@id/firstView"

加入这个对齐会发现如下:


在上面会有一个绿色下划线,这就是基准线。为了便于观察基准线的作用,可以将字体该的大一点

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/firstView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FF0000"
        android:textSize="30sp"
        android:text="Hello" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#00FF00"
        android:layout_toRightOf="@id/firstView"
        android:layout_alignBaseline="@id/firstView"
        android:text="TextView" />
</RelativeLayout>
效果:

从上图可以看到,不管Hello的字体有多大,TextView都是和它的基准线对齐的。

与父控件边缘对齐的几个属性:

1   android:layout_alignParentLeft  
2   android:layout_alignParentRight  
3   android:layout_alignParentTop  
4   android:layout_alignParentBottom 

实验android:layout_alignParentRight="true"


这个Hello的父控件就是总的相对布局其他类似


对齐至父控件的中央  
1   android:layout_centerInParent  
2   android:layout_centerHorizontal  
3   android:layout_centerVertical

以android:layout_centerInParent为例:

  



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值