LinearLayout(线性布局)
要点:
android:orientation="vertical"垂直线性布局,"horizontal"水平线性布局
android:gravity="top"(buttom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical、clip_horizontal)控制布局中控件的对齐方式。如果是没有子控件的控件设置此属性,表示其内容的对齐方式,比如说TextView里面文字的对齐方式;若是有子控件的控件设置此属性,则表示其子控件的对齐方式,gravity如果需要设置多个属性值,需要使用“|”进行组合
android:gravity 与 android:layout_gravity的区别
android:gravity是指定本元素的子元素相对它的对齐方式。
android:layout_gravity是指定本元素相对它的父元素的对齐方式。
android:layout_weight="1"通过设置控件的layout_weight属性以控制各个控件在布局中的相对大小,线性布局会根据该控件layout_weight值与其所处布局中所有控件layout_weight值之和的比值为该控件分配占用的区域。在水平布局的LinearLayout中有两个Button,这两个Button的layout_weight属性值都为1,那么这两个按钮都会被拉伸到整个屏幕宽度的一半。如果layout_weight指为0,控件会按原大小显示,不会被拉伸;对于其余layout_weight属性值大于0的控件,系统将会减去layout_weight属性值为0的控件的宽度或者高度,再用剩余的宽度或高度按相应的比例来分配每一个控件显示的宽度或高度。
如:
代码如下:
<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"tools:context=".LinearLayoutActivity" ><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:orientation="horizontal" ><Buttonandroid:layout_width="wrap_content"android:layout_height="match_parent"android:layout_weight="1"android:background="#aa0000"android:gravity="center_horizontal|center_vertical"android:text="第一列"android:textSize="15sp" ></Button><Buttonandroid:layout_width="wrap_content"android:layout_height="match_parent"android:layout_weight="1"android:background="#00aa00"android:gravity="center_horizontal"android:text="第二列"android:textSize="15sp" ></Button><Buttonandroid:layout_width="wrap_content"android:layout_height="match_parent"android:layout_weight="1"android:background="#0000aa"android:gravity="center|bottom"android:text="第三列"android:textSize="15sp" ></Button><Buttonandroid:layout_width="wrap_content"android:layout_height="match_parent"android:layout_weight="1"android:background="#aaaa00"android:gravity="bottom"android:text="第四列"android:textSize="15sp" ></Button></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:orientation="vertical" ><Buttonandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:gravity="bottom"android:text="第1行"android:textSize="15sp" ></Button><Buttonandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:gravity="bottom"android:text="第2行"android:textSize="15sp" ></Button><Buttonandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:gravity="bottom"android:text="第3行"android:textSize="15sp" ></Button><Buttonandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:gravity="bottom"android:text="第4行"android:textSize="15sp" ></Button></LinearLayout></LinearLayout>
LinearLayout(线性布局)相关推荐
- Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件...
UI的描述 对于Android应用程序中,所有用户界面元素都是由View和ViewGroup对象构建的.View是绘制在屏幕上能与用户进行交互的一个对象.而对于ViewGroup来说,则是一个用于存放 ...
- Android零基础入门第25节:最简单最常用的LinearLayout线性布局
原文:Android零基础入门第25节:最简单最常用的LinearLayout线性布局 良好的布局设计对于UI界面至关重要,在前面也简单介绍过,目前Android中的布局主要有6种,创建的布局文件默认 ...
- 精通android布局,Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件...
标题图 UI的描述 对于Android应用程序中,所有用户界面元素都是由View和ViewGroup对象构建的.View是绘制在屏幕上能与用户进行交互的一个对象.而对于ViewGroup来说,则是一个 ...
- Android 应用开发(36)---LinearLayout(线性布局)
LinearLayout(线性布局) 本节开始讲Android中的布局,Android中有六大布局,分别是: LinearLayout(线性布局),RelativeLayout(相对布局),Table ...
- 常见界面布局之LinearLayout线性布局
1.什么是LinearLayout线性布局 LinearLayout (线性布局)通常指定布局内的子控件水平或者轻直排列.在XML布局文件中定义线性布局的基本语法格式如下: <LinearLay ...
- new UI-布局之LinearLayout(线性布局)详解
转载自:http://blog.csdn.net/coder_pig/article/details/42344615 --转载请注明出处:coder-pig,欢迎转载,请勿用于商业用途! 小猪An ...
- 3.2.1 LinearLayout(线性布局)
3.2.1 LinearLayout(线性布局) 标签: StudyNote 本文声明: 本文由Coder-pig编写,想了解其他内容,可见CoderPig's Android Study Note- ...
- java 界面线性布局_布局Layouts之LinearLayout线性布局
从Hello world!开始,我们一直都是在一种布局下学习的,当然,对于基础内容的学习,还是没有任何问题的!但-- 在Android开发中UI设计也是十分重要的,当用户使用一个App时,最先感受到的 ...
- android线性布局设置控件固定在底部,Android UI组件LinearLayout线性布局详解
LinearLayout 线性布局,该布局的继承关系: 1. 什么是线性布局 通俗的说感觉起来和线有关,参照线的特点,有么是横向的,要么是竖向的. LinearLayout是线性布局控件,它包含的子控 ...
- 【Android 】零基础到飞升 | LinearLayout(线性布局)
2.2.1 LinearLayout(线性布局) 本节引言 本节开始讲Android中的布局,Android中有六大布局,分别是: LinearLayout(线性布局),RelativeLayout( ...
最新文章
- 2012-08-17
- 开的什么源?——第三篇:草根创业
- wxWidgets:wxNavigationKeyEvent类用法
- MySQL中的information_schema
- FPGA时钟激励编写(方法四)
- 沧小海笔记之PCIE协议解析——第一章 PCIE概述(下)
- 软考(中级软件设计师)考试信息
- Pine脚本 | 如何编写移动平均线?(附案例)
- Google算法更新记录-你想了解的全在这
- 网页: 如何修改列表项 ul > li 前小圆点的样式
- linux link/symlink/unlink 硬连接和软连接介绍
- 关于数据中台、数据平台、数据仓库、数据湖等数据概念的对比解析
- 【拓扑学知识】4.拓扑性质--分离公理与可数公理(分离性和可数性)
- 实体、协议、服务和服务访问点的概念
- GPL amp; LGPL
- 解决Chrome 无法保存密码问题
- 与黑客讨价还价,勒索攻击企业数据是关键
- 桂林电子科技大学计算机学院钟艳如,桂林电子科技大学考研研究生导师简介-钟艳如...
- 从零开始编译OpenWrt固件
- 风速 电池测试软件,QDF-6型智能热球风速计操作规程
热门文章
- C#语法之Linq查询基础一
- Knockoutjs Component问题汇总
- 自制简易AP柱面定向天线(zz)
- 根据时间格式字符串取出时分秒各自的数值
- Bootstrap+PHP fileinput 实现多图上传 这是ajax上传,只能单张单张图片地上传
- 关于inet_ntop、inet_pton中的n和p分别代表的意义
- The Elder HDU - 5956
- [转] MemCached 的 stats 命令
- 浅析 public static void main(String[] args)
- Docker系列06—基于容器制作镜像并上传到Docker Registry