首页 > 移动平台 > 详细

Android: RelativeLayout中的baseline是什么?

时间:2015-03-01 00:11:57      阅读:531      评论:0      收藏:0      [点我收藏+]

转载自: http://www.cnblogs.com/loulijun/archive/2012/10/17/2727580.html

中文翻译是基准线的意思,看似简单又有些不好理解,其实这个baseline相当于笔记本里写文字时候的底下的那条线,在RelativeLayout中baseline举例:

比如,加入两个相邻的TextView,给第二个TextView一个大一点的padding(比如20dp),如果加了layout_alignBaseline到第二个TextView中的话,TextView中的文字"world"会与第一个TextView中的"hello"处于同一水平线,第二个TextView控件是上移了,就好像是"hello"和"world"处于同一条线上,如果没有加layout_alignBaseline,具体看下面效果图

技术分享
<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/text1"
        android:text="hello"
        android:background="#aa0000"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />    
        <TextView
            android:text="world"
            android:background="#00ff00"
            android:padding="20dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/text1"
            android:layout_alignBaseline="@id/text1"
            />
</RelativeLayout>
技术分享

 

1:未加layout_alignBaseline

技术分享

2:加layout_alignBaseline,就像两排文字hello world在一条线上写的

技术分享

3:测试垂直方面,将第二个TextView设置为layout_below属性,未加layout_alignBaseline

技术分享

4、测试垂直方面,将第二个TextView设置为layout_below属性,加layout_alignBaseline。可以看到,它是将上面的控件覆盖了,但是并没有垂直居中

技术分享

Android: RelativeLayout中的baseline是什么?

原文:http://www.cnblogs.com/zhzhy126/p/4306381.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!