安卓开发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 ...
随机推荐
- java中只能有一个实例的类的创建
Java中,如果我们创建一个类,想让这个类只有一个对象,那么我们可以 1:把该类的构造方法设计为private 2:在该类中定义一个static方法,在该方法中创建对象 package test; / ...
- 比赛F-F Perpetuum Mobile
比赛F-F Perpetuum Mobile 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/ ...
- windows cmd: 打开windows系统程序或服务的常见命令
Windows常用CMD命令 http://www.cnblogs.com/sbaicl/archive/2013/03/05/2944001.html 其实查找Windows自带程序的命令行很简单, ...
- XPath与多线程爬虫
XPath是一门在xml中查询信息的语言安装使用XPath 1.安装lxml库 window:pip install lxmllinux:sudo pip install lxml国内安装缓慢,建议到 ...
- Average(模拟)
Average Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tota ...
- ThinkPHP - 自定义扩展类库
首先在想要使用类库的地方建立文件夹,文件名称随意,不能使用class 然后在配置文件中: 'AUTOLOAD_NAMESPACE' => array( 'Lib' => './Lib', ...
- 【Eclipse】离线插件安装
1.在eclipse里根目录里,dropins里建一个目录,名字叫sonar(这个名字随便),再在svn下面建一个目录eclipse.在根目录里建一个目录links目录,并建一个sonar.link文 ...
- 键盘过滤第一个例子ctrl2cap(4.1~4.4)汇总,测试
键盘过滤第一个例子ctrl2cap(4.1~4.4)汇总,测试 完整源代码 /// /// @file ctrl2cap.c /// @author wowocock /// @date 2009-1 ...
- 使用DiskGenius对虚拟机磁盘进行压缩
使用虚拟机的用户是否感觉到您的虚拟磁盘文件越来越大,都快把宝贵的磁盘空间(宿主机物理硬盘)占满了呢? 有人会想到,我直接启动虚拟机,然后把里面没用的数据删除了,不就行了吗?实际测试发现,这样删除后,存 ...
- Python函数式编程:内置filter函数使用说明
filter操作是函数式编程中对集合的重要操作之一,其作用是从原集合中筛选符合条件的条目,组成一个新的集合. 这在我们日常编程中是非常常见的操作.我们通常的做法是通过循环语句来处理. 而使用filte ...