android_layout_linearlayout(一)
这几天一直在研究线性布局这块,记录下一些研究心得,作为参考之用。
一、金刚钻:(线性布局,英文名 linearLayout)
布局xml文件中统大者是一个线性布局,它的长宽都已经fill_parent沾满了整个屏幕,因此想再在线性布局外再搞一个控件是不可能的。如果将统大者线性布局的高度设置为wrap_content(我称之为适可而止)也不行,这点我已经做过实验。不过,可以在统大者线性布局中搞其他布局与控件是可以的;
线性布局设置的是垂直方向,控件之间的关系是上下排列,一般人拿着手机是竖方向,也就是垂直方向;若切换为横屏,此时是水平方向,控件之间依然是上下排列。不管线性布局设置为垂直,还是水平,控件之间都是上下排列。
二、几个布局xml文件
1. look
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="I am textview 1"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="I am textview 2"/>
</LinearLayout>
对应的效果:
可以看到,第二个文本框并没有显示。我分析,线性布局沾满整个屏幕,两个文本框是水平排列在同一行,第一个文本框的宽度是沾满一整行,第二个文本框被挤压出界面,离开我们的视线。
2. look
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
android:layout_width="10px"
android:layout_height="wrap_content"
android:text="I am textview 1"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="I am textview 2"/>
</LinearLayout>
效果图
第一个文本框的宽度改为10px,因此,两个文本框此时是可以同行显示。第一个文本框的宽度是10px,因此无法在同一行显示所有的文本,还好高度是适可而止的,其余的文本就一个个向下显示。第二个文本框的宽度是横着沾满整个屏幕的(不过没有覆盖第一个文本的I字符,我的想象中第二个文本的I字符会与第一个文本框的I字符重叠),它的文本是可以全部显示在一行上。
3. look
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
android:layout_width="30px"
android:layout_height="wrap_content"
android:text="I am textview 1"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="I am textview 2"/>
</LinearLayout>
效果图
第一个文本的宽度改为30px,它的文本可以在一行中多显示几个字符,应该是4个字符(我没理解为什么第一行仍然只显示一个字符I,我认为am也应该显示在第一行上)。第二个文本框就是横着沾满一个屏幕,但是仍然没有覆盖掉第一个文本,否则它的文本第一个字符I应该与第一个文本框的首个字符I重叠,它所有的文本是从第31个px开始显示吧。
统大者线性布局,一般是要沾满整个屏幕,如果是沾满整个屏幕的话,那么它的方向的垂直与水平决定了布局中的子元素是垂直排列还是横向排列,不是说这个布局是垂直得看还是水平地看。
4. look
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="I am textview 1"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="I am textview 2"/>
</LinearLayout>
效果图
两个按钮的宽度沾满整个行(默认左右上下预留点空隙),高度适可而止。可以看到,下面整个屏幕就空间一片黑暗,都浪费了。
5. look
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am textview 1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am textview 2"/>
</LinearLayout>
效果图
两个按钮的高宽度均为适可而止,因此随着文本的多少恰当的显示;
6. look
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am textview 1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am textview 2"
android:layout_weight="1"/>
</LinearLayout>
效果图
第二个按钮给了它一个权重,这就意味着屏幕剩余的黑暗空间都给它了;第一个按钮的权重默认是0,所以按部就班的原样显示;
三、暂时总结
对linearlayout线性布局的研究暂时就这么多,我想可能还远远不够。吃透线性布局还需要进一步的研究,在实战中研究,因此这篇博文还需要完善和扩充。
android_layout_linearlayout(一)的更多相关文章
- android_layout_linearlayout(二)
android的线性布局linearlayout的研究没有尽头.看了官网关于线性布局的一个例子,捣鼓一阵,发现的迷惑记录在此. 一.先看看官网xml <?xml version="1. ...
随机推荐
- C# DataGridView合计行
在网上搜了很多关于DataGridView合计行的设计及源码,都不是很合我心意.于是自己写了一个关于合计行的DLL.以后每次要用到合计行的时候只要引用这个DLL就可以了. 效果图如下: 引用Dll: ...
- Delphi 导出数据至Excel的7种方法
一; delphi 快速导出excel uses ComObj,clipbrd; function ToExcel(sfilename:string; ADOQuery:TADOQuery):bool ...
- Linux日志系统
常见的日志 常见的日志一般存储在/var/log中.常见的日志查看使用:ls/ll,cat/more/less查看即可:wtmp,lastlog使用last和lastlog提取其信息即可 配置日志 较 ...
- uwp汉堡菜单的实现
---恢复内容开始--- 现在uwp上面的汉堡菜单(就是那个三道杠,点击之后会出现菜单)使用的越来越普遍,比如微软自己家的Cortana.现在我使用的实现方法是使用SplitView实现.首先Spli ...
- SSL Converter & Formats
https://www.sslshopper.com/ssl-converter.html PEM Format The PEM format is the most common format th ...
- 【MyEclipse常见错误】-java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory的解决
ApacheJavaTomcatMyeclipse 自己前一段时间出现了这个问题,通过在网上搜索,大概知道了原因,整理下一,以供大家参考. 将项目部署好后,启动tomcat后报错,java.lang ...
- Java对象结构及HotSpot对象模型
一.对象结构 在HotSpot虚拟机中,对象在内存中存储的布局可以分为3块区域:对象头(Header).实例数据(Instance Data)和对齐填充(Padding).下图是普通对象实例与数组对象 ...
- ElasticSearch2.3.1环境搭建哪些不为人知的坑
首先说明一点,大家最好不要用什么尝鲜版,用比稳定版就好了,要不麻烦不断,另外出了问题,最好去官网,或者google搜索,因为这样靠谱些,要不现在好多都是低版本的,1.4的什么的,结果按照安装,多少情况 ...
- bean 解析、注册、实例化流程源码剖析
本spring源码的版本:4.3.7 Spring bean的加载主要分为以下6步: (1)读取XML配置文件 (2)XML文件解析为document文档 (3)解析bean (4)注册bean (5 ...
- 浅入深出Vue:数据渲染
今天来正式开始 vue的学习,首当其冲的当然是数据的渲染.毕竟数据就是拿来看的,看看如果使用 vue来展示数据. 为什么渲染 俗话说 "人靠衣装马靠鞍", 那咱们的代码就是得靠 U ...