安卓开发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 ...
随机推荐
- 融合python2和python3
很多情况下你可能会想要开发一个程序能同时在python2和python3中运行. 想象一下你开发了一个模块,成百上千的人都在使用它,但不是所有的用户都同时使用python 2和3.这种情况下你有两个选 ...
- JavaScript学习笔记2-数组对象
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 监测scroll
$(window).scroll(function() { var scrollValue = $(this).scrollTop(); var h=200+scrollValue; $('.yui3 ...
- 单点登录 .NET MVC
原文:单点登录 .NET MVC CAS 实现单点登录 .NET MVC 单点登录 Single Sign On,简称为 SSO,是目前比较流行的企业业务整合的解决方案之一.SSO的定义是在多个应 ...
- Linux学习:find、chmod、ps命令
下面介绍下linux下find.chmod.ps这三个常见命令的使用. 这每个命令都有很多可选的参数,不同参数体现的功能不一样.我们这里不一一介绍各种参数的含义,只介绍最常见的使用场景. 一.find ...
- github的.md格式文件
md文件是github改良了markdown的语法,用来显示在项目首页的文件.在官方的网址说的很清楚: GitHub uses what we're calling "GitHub Flav ...
- IBM 中国研究院面试经历
继上次面试MSRA失败后,严重刺激了我幼小的心灵.从此苦学算法准备面试很多其它其它的公司刷一刷Offer以解心 头之恨. 这个带来的IBM 中国研究院的面试经历. IBM的面试相比于MSRA.简直就是 ...
- javascript 学习随笔3
<html> <head> <script type="text/javascript"> function startTime() { var ...
- [转]CentO下限制SSH登录次数
应公司内部网站等级测评的需求,正逐渐加强系统安全防护. 设备默认 3 次验证失败自动退出,并且结束会话:网络登录连接超时自动退出时间 5 分钟: 第一种方法:已验证. 1.ssh超时时间设置 # cd ...
- js中innerHTML与innerText的用法与区别
用法: <div id="test"> <span style="color:red">test1</span> te ...