LinearLayout (线性布局)的分析
android提供了5中布局,线性布局,相对布局,帧布局。表格布局和绝对布局
线性和相对布局用的是最多的
以下要说的是线性布局
提到线性布局 一定要记住。它里面的全部组件一定不会重叠的,
切不会换行。当组件排列到窗口的边缘后,后面的组件不会显示不来。
线性布局是将放入当中的组件依照水平或者垂直方向来布局的,
线性布局的语法:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
属性列表
</LinearLayout>
简单的写一个:
<LinearLayout 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"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#66ff66"
android:textSize="25sp"
android:text="面码" /> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:background="#ff0000"
android:text="小木" /> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:background="#ffcc33"
android:text="小桃" /> </LinearLayout>
效果图:
这个是垂直方向排列的,
线性布局中经常使用的属性:
android:orientation 指定线性布局排列的方向。其值有vertical是垂直horizontal是水平。
andorid:gravity 布局管理器内组件的对其方法。上下左右,这个前面已经说了,这里
在提起是想说当同一时候指定多个属性的时候中间用|分开 比如left|bottom.
android:layout_width 指定组件的宽度,其值有fill_parent,match_parent,wrap_content,
当中fill_parent和match_parent作用同样。表示组件的宽度与父容器的宽度同样。
(android2.2之后推荐使用match_parent)
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#66ff66"
android:textSize="25sp"
android:text="面码" />
比如这个textview 的宽度就是和手机屏幕的宽度一样。
wrap_content表示该组件的宽度恰好和它的宽度一样
比如上面textview的高度。这个高度和字体的高度一样的。
android:layout_height 指定组件的高度。里面的值和宽度一样
android:id 指定当前组件的一个id属性。 这个指定之后android会在
R.java中自己主动生成唯一的id值。
android:weight 权重,这个就不再说了,不理解的參考
http://blog.csdn.net/qq_33210042/article/details/50907811
android:background 指定组件的背景, 这个要说下它的指定方法
1 直接使用颜色值就像我上面的代码android:background="#ffcc33"
2 调用图片anroid:background="drawable/图片的名字"
3 使用android系统自带的 android:background="@android:color/white"
android:visibility 指定布局中的组件是否显示,gone 隐藏,visible显示。
invisible不显示但赞内存
以下说一个线性布局的技巧(这个老师教的):
先看代码:
<LinearLayout 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"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#66ff66"
android:textSize="25sp"
android:layout_gravity="right"
android:text="面码" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:background="#ff0000"
android:layout_gravity="left"
android:text="小木" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:background="#ffcc33"
android:layout_gravity="top"
android:text="小桃" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:background="#ffcc33"
android:layout_gravity="center"
android:text="小桃" /> </LinearLayout>
看图能发现top没有效果了, 设置成bottom一样没有效果
这里总结下:
线性布局 是竖直方向是,左右对齐有效,顶部底部对齐无效。水平
居中生效。竖直居中无效,
在水平方向上则是反过来的,有兴趣的童鞋能够试试。
LinearLayout (线性布局)的分析的更多相关文章
- android 59 LinearLayout 线性布局
##常见的布局* LinearLayout 线性布局线性布局往左右拉是拉不动的,> 线性布局的朝向 vertical|horizontal> 线性布局的权重 weight 和 0dip一起 ...
- Android布局管理详解(1)—— LinearLayout 线性布局
Android的布局方式共有6种,分别是LinearLayout(线性布局).TableLayout(表格布局).FrameLayout(帧布局).RelativeLayout(相对布局).GridL ...
- Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件
UI的描述 对于Android应用程序中,所有用户界面元素都是由View和ViewGroup对象构建的.View是绘制在屏幕上能与用户进行交互的一个对象.而对于ViewGroup来说,则是一个用于存放 ...
- 2.2.1 LinearLayout(线性布局)
本节引言 本节开始讲Android中的布局,Android中有六大布局,分别是: LinearLayout(线性布局), RelativeLayout(相对布局), TableLayout(表格布局) ...
- Android零基础入门第25节:最简单最常用的LinearLayout线性布局
原文:Android零基础入门第25节:最简单最常用的LinearLayout线性布局 良好的布局设计对于UI界面至关重要,在前面也简单介绍过,目前Android中的布局主要有6种,创建的布局文件默认 ...
- LinearLayout线性布局搭配权重属性的使用
在开发中,我们是通过布局来完成应用界面的搭配的,通过各种布局,我们可以完成各种复杂的界面设计.而LinearLayout也就是我们说的线性布局,这个比较简单而且使用很广泛的一种布局.下面我们通过一个D ...
- Android LinearLayout线性布局
LinearLayout是线性布局控件:要么横向排布,要么竖向排布 决定性属性:必须有的! android:orientation:vertical (垂直方向) .horizontal(水平方向) ...
- LinearLayout线性布局
作用 : 线性布局会将容器中的组件一个一个排列起来, LinearLayout可以控制组件横向或者纵向排列, 通过android:orientation属性控制; 不换行属性 : 线性布局中的组件不会 ...
- LinearLayout 线性布局
android:orientation 设置布局管理器内组件的排列方式,可设置为 horizontal (水平排列).vertical (垂直排列) android:gravity 设置布局管理器内组 ...
- Android LinearLayout线性布局详解
为了更好地管理Android应用的用户界面里的各组件,Android提供了布局管理器.通过使用布局管理器,Android应用图形用户界面具有良好的平台无关性.推荐使用布局管理器来管理组件的分布.大小, ...
随机推荐
- Spring scheduled cron 表达式
一个cron表达式有至少6个(也可能7个)有空格分隔的时间元素. 按顺序依次为 秒(0~59) 分钟(0~59) 小时(0~23) 天(月)(0~31,但是你需要考虑你月的天数) 月(0~11) 天( ...
- windows服务器修改远程登录的端口+防火墙配置
话不多说,一个bat文件,快速修改注册表端口.你只需要做的是另外防火墙添加例外端口后重启即可.经测试2008-2012-2016-2019正常使用! @echo off rem 查找端口号 for / ...
- @ControllerAdvice全局异常拦截
@ControllerAdvice 拦截异常并统一处理 在spring 3.2中,新增了@ControllerAdvice 注解,可以用于定义@ExceptionHandler.@InitBinder ...
- oracle文件 结构01
1.减少数据的冗余(例如使用id) 2.保证数据库一致性 关联表越多越慢 主机名 hosts 文件 ntp 时间同步
- API Studio 5.1.2 版本更新:加入全局搜索、支持批量测试API测试用例、读取代码注解生成文档支持Github与码云等
最近在EOLINKER的开发任务繁重,许久在博客园没有更新产品动态了,经过这些日子,EOLINKER又有了长足的进步,增加了更多易用的功能,比如加入全局搜索.支持批量测试API测试用例.读取代码注解生 ...
- 话说Form标签的target属性-----无刷新表单提交
国庆前(2013)无聊,就在铁道部的12306上“逛”了下下. PS:原来之所以叫12306,是因为其客服号码是12306,好吧,我很无知…… 首先是被“逛”的页面:票价查询. 之所以去逛,是因为一直 ...
- Vue.js 计算属性(computed)
Vue.js 计算属性(computed) 如果在模板中使用一些复杂的表达式,会让模板显得过于繁重,且后期难以维护.对此,vue.js 提供了计算属性(computed),你可以把这些复杂的表达式写到 ...
- 深入理解PHP之foreach
招聘 标签(空格分隔): 招聘 PHP 国贸 语言基础 foreach 语法结构提供了遍历数组的简单方式. php5之前, foreach仅能用于数组php5+, 利用foreach可以遍历对象 fo ...
- java 十三周总结
- Django-REST-Framework JWT 实现SSO认证(下)
在上一篇博客中,我已经对JSON Web 认证做了简单的解释,这篇博客是续篇,若不了解,请看上一篇博客:https://www.cnblogs.com/yushenglin/p/10863184.ht ...