安卓开发06:布局-线性布局 LinearLayout
LinearLayout把视图组织成一行或一列。子视图能被安排成垂直的或水平的。线性布局是非常常用的一种布局方式。
请看一个布局例子:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <!-- 大的框架,横着布局 --> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" > <!-- 线性布局-竖着布局 --> <LinearLayout
android:layout_width="100dp"
android:layout_height="fill_parent"
android:orientation="vertical" > <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1" /> <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2" />
</LinearLayout> <!-- 线性布局-横着着布局 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button3" /> <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button4" />
</LinearLayout>
</LinearLayout> </LinearLayout>
效果图:
线性布局框架的一个属性表:
| 属性 | 描述 |
| layout_width | 指定View或ViewGroup的宽度 |
| layout_height | 指定View或ViewGroup的高度 |
| layout_marginTop | 指定View或ViewGroup上方的额外空间 |
| layout_marginBottom | 指定View或ViewGroup下方的额外空间 |
| layout_marginLeft | 指定View或ViewGroup左侧的额外空间 |
| layout_marginRight | 指定View或ViewGroup右侧的额外空间 |
| layout_gravity | 指定View或ViewGroup中的子视图的排列位置 |
| layout_weight | 指定指派给View或ViewGroup的额外空间尺寸 |
| layout_x | 指定View或ViewGroup的x坐标 |
| layout_y | 指定View或ViewGroup的y坐标 |
可以看到layout_width和layout_hight中经常有fill_parent,wrap_content,match_parent来区分宽度和高度。这三者什么区别呢?
fill_parent:
设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间。这跟Windows控件的dockstyle属性大体一致。设置一个顶部布局或控件为fill_parent将强制性让它布满整个屏幕。
wrap_content:
设置一个视图的尺寸为wrap_content将强制性地使视图扩展以显示全部内容。以TextView和ImageView控件为例,设置为wrap_content将完整显示其内部的文本和图像。布局元素将根据内容更改大小。设置一个视图的尺寸为wrap_content大体等同于设置Windows控件的Autosize属性为True。
match_parent:
Android2.2中match_parent和fill_parent是一个意思 .两个参数意思一样,match_parent更贴切,于是从2.2开始两个词都可以用。那么如果考虑低版本的使用情况你就需要用fill_parent了
安卓开发06:布局-线性布局 LinearLayout的更多相关文章
- 安卓开发:UI组件-布局管理器和文本显示
接下来的随笔,记录了在学习b站up主:天哥在奔跑,录制的教学视频的同时,进行一个app开发. up主:天哥在奔跑 视频地址:https://www.bilibili.com/video/av38409 ...
- 安卓开发:初步了解布局文件layout
了解完项目的目录结构,主要文件的作用之后. 了解完各常量文件的定义和使用之后,接下来的重头戏肯定是布局文件layout. 果然,网上关于“安卓布局文件layout”的各种介绍.解析.深入分析,等等资料 ...
- Android布局— — —线性布局
以水平或垂直的方式显示界面中的控件 线性布局 语法格式: <LinearLayout xmlns:android="http://schemas.android.com/apk/res ...
- Android笔记(七) Android中的布局——线性布局
我们的软件是由好多个界面组成的,而每个界面又由N多个控件组成,Android中借助布局来让各个空间有条不紊的摆放在界面上. 可以把布局看作是一个可以放置很多控件的容器,它可以按照一定的规律调整控件的位 ...
- 安卓开发24:FrameLayout布局
FrameLayout布局 FrameLayout是五大布局中最简单的一个布局.FrameLayout布局中的元素会根据先后顺序重叠起来.利用FrameLayout布局元素重叠的特性,我们一般可以做一 ...
- 安卓开发创建活动,布局,添加按钮,she使用Toast,设菜单,使菜单相关联等操作
---恢复内容开始--- 创建一个新活动在app/src/main/java/com.example.activitytest ,然后右击com.example.activitytest包→New→A ...
- 安卓开发-使用XML菜单布局简单介绍
使用xml布局菜单 目前为止我们都是通过硬编码来增加菜单项的,android为此提供了一种更便利的方式,就是把menu也定义为应用程序的资源,通过android对资源的本地支持,使我们可以更方便地 ...
- android 59 LinearLayout 线性布局
##常见的布局* LinearLayout 线性布局线性布局往左右拉是拉不动的,> 线性布局的朝向 vertical|horizontal> 线性布局的权重 weight 和 0dip一起 ...
- Android线性布局(Linear Layout)
Android线性布局(Linear Layout) LinearLayout是一个view组(view group),其包含的所有子view都以一个方向排列,垂直或是水平方向.我们能够用androi ...
随机推荐
- [转]SAP中找表的方法
http://blog.chinaunix.net/uid-24063584-id-2642334.html 分类: 18种根据屏幕字段查找数据库表数据的技巧 帮助 18种根据屏幕字段查找潜在数据 ...
- vs2010中iostream.h出错
使用 #include <iostream> using namespace std; 替代 VS2010删除了所有非标准库,保留了C++标准库,iostream.h是以前旧版的库,VS2 ...
- xml校验问题
struts2使用xml校验 按照书本输入dtd约束文件 "-//OpenSymphony Group//XWork Validator 1.0.2//EN""http: ...
- LinuxC安装gcc
使用centos进行C编程的时候使用gcc hello.c提示 bash:gcc:command not found 此时需要给Linux安装gcc命令如下 1 yum -y install gcc ...
- 通过Qt样式表定制程序外观(比较通俗易懂)
1. 何为Qt样式表[喝小酒的网摘]http://blog.hehehehehe.cn/a/10270.htm2. 样式表语法基础3. 方箱模型4. 前景与背景5. 创建可缩放样式6. 控制大小7. ...
- elk工作原理
这个配置文件,是读取nginx日志写入到redis zjtest7-redis:/usr/local/logstash-2.3.4/config# cat logstash_agent.conf in ...
- 《Clean Code》重点内容总结
读书笔记请见Github博客:http://wuxichen.github.io/Myblog/reading/2014/10/06/CleanCode.html
- [上海] 携程 门票事业部 招聘.NET 架构师 2 名 - V2EX
[上海] 携程 门票事业部 招聘.NET 架构师 2 名 - V2EX [上海] 携程 门票事业部 招聘.NET 架构师 2 名
- BZOJ 2016: [Usaco2010]Chocolate Eating( 二分答案 )
因为没注意到long long 就 TLE 了... 二分一下答案就Ok了.. ------------------------------------------------------------ ...
- Js 30 BOM
小知识点, 1.document.write()方法: 如果document.write()在一个事件中或window.onload=function(){}这个function里, 那么docume ...