Android 布局LinearLayout——属性baselineAligned的作用及baseline
2015-10-14 23:14
706 查看
相信大家对LinearLayout已经相当熟悉,但你们是否了解它的属性baselineAligned呢?
Android官方文档是这么描述的:
![](https://oscdn.geek-share.com/Uploads/Images/Content/201911/04/4eb929c897db98e257aeb9c63a147cba)
那到底这个属性是做什么用的呢?
baselineAligned:基准线对齐。
首先要解释什么是基准线,这个在中文中不常见,但在以字母为书写语言的其他国家非常常见。
![](https://oscdn.geek-share.com/Uploads/Images/Content/201911/04/54245684c2f417dd4dab0ba0bf801f8f)
如上图所示,红线就是基线(baseline),是不是很熟悉,这不就是我们经常写英文的四条线中的第三条吗。
![](https://oscdn.geek-share.com/Uploads/Images/Content/201911/04/89e48318a27fbbd6e1a5b7376e8133a7)
那baselineAligned是做什么用的呢?根据官方文档,baselineAligned默认设置为true,当设置为false时,
布局文件和它的子组件的基准线不对齐。
让我们通过一个例子来看看效果怎样的。
这是将baselineAligned值设置为false时,也就是不对齐。看看运行效果:
![](https://oscdn.geek-share.com/Uploads/Images/Content/201911/04/b65e0732f55f70eb8c6b0f266b49b57e)
把baselineAligned值改为true。
![](https://oscdn.geek-share.com/Uploads/Images/Content/201911/04/ad59a7eb30b08146bbdeaa27edb0059c)
看,差别明显,这样就很好的理解了baselineAligned的作用了。其实,这个并不难,但我觉得不管难不难,只要不明白,就应该多思考,想想为什么。
Android官方文档是这么描述的:
那到底这个属性是做什么用的呢?
baselineAligned:基准线对齐。
首先要解释什么是基准线,这个在中文中不常见,但在以字母为书写语言的其他国家非常常见。
如上图所示,红线就是基线(baseline),是不是很熟悉,这不就是我们经常写英文的四条线中的第三条吗。
那baselineAligned是做什么用的呢?根据官方文档,baselineAligned默认设置为true,当设置为false时,
布局文件和它的子组件的基准线不对齐。
让我们通过一个例子来看看效果怎样的。
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="wrap_content" 5 android:baselineAligned="false" 6 android:orientation="horizontal"> 7 8 <TextView 9 android:layout_width="wrap_content" 10 android:layout_height="wrap_content" 11 android:layout_marginRight="5dip" 12 android:text="TextView:p" /> 13 <TextView 14 android:layout_width="wrap_content" 15 android:layout_height="wrap_content" 16 android:layout_marginRight="5dip" 17 android:textSize="30sp" 18 android:text="LargeTextView:p" 19 /> 20 </LinearLayout>
这是将baselineAligned值设置为false时,也就是不对齐。看看运行效果:
把baselineAligned值改为true。
看,差别明显,这样就很好的理解了baselineAligned的作用了。其实,这个并不难,但我觉得不管难不难,只要不明白,就应该多思考,想想为什么。
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题