layout_gravity 和 gravity以及对应值的详解
gravity 这个英文单词是重心的意思,在这里就表示停靠位置的意思。
android:layout_gravity 和 android:gravity 的区别
从名字上可以看到,android:gravity是对元素本身说的,元素本身的文本显示在什么地方靠着换个属性设置,不过不设置默认是在左侧的。
android:layout_gravity是相对与它的父元素说的,说明元素显示在父元素的什么位置。
比如说button: android:layout_gravity 表示按钮在界面上的位置。 android:gravity表示button上的字在button上的位置。
可选值
这两个属性可选的值有:top、bottom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical。
而且这些属性是可以多选的,用“|”分开。
默认这个的值是:Gravity.LEFT
对这些属性的描述:
出自:
http://androidmirror.com/guide/topics/resources/drawable-resource.html
http://android.toolib.net/reference/android/graphics/drawable/ClipDrawable.html
Value | Description |
top |
Put the object at the top of its container, not changing its size. 将对象放在其容器的顶部,不改变其大小. |
bottom |
Put the object at the bottom of its container, not changing its size. 将对象放在其容器的底部,不改变其大小. |
left |
Put the object at the left edge of its container, not changing its size. 将对象放在其容器的左侧,不改变其大小. |
right |
Put the object at the right edge of its container, not changing its size. 将对象放在其容器的右侧,不改变其大小. |
center_vertical |
Place object in the vertical center of its container, not changing its size. 将对象纵向居中,不改变其大小. 垂直对齐方式:垂直方向上居中对齐。 |
fill_vertical |
Grow the vertical size of the object if needed so it completely fills its container. 必要的时候增加对象的纵向大小,以完全充满其容器. 垂直方向填充 |
center_horizontal |
Place object in the horizontal center of its container, not changing its size. 将对象横向居中,不改变其大小. 水平对齐方式:水平方向上居中对齐 |
fill_horizontal |
Grow the horizontal size of the object if needed so it completely fills its container. 必要的时候增加对象的横向大小,以完全充满其容器. 水平方向填充 |
center |
Place the object in the center of its container in both the vertical and horizontal axis, not changing its size. 将对象横纵居中,不改变其大小. |
fill |
Grow the horizontal and vertical size of the object if needed so it completely fills its container. This is the default. 必要的时候增加对象的横纵向大小,以完全充满其容器. |
clip_vertical |
Additional option that can be set to have the top and/or bottom edges of the child clipped to its container’s bounds. The clip is based on the vertical gravity: a top gravity clips the bottom edge, a bottom gravity clips the top edge, and neither clips both edges.
附加选项,用于按照容器的边来剪切对象的顶部和/或底部的内容. 剪切基于其纵向对齐设置:顶部对齐时,剪切底部;底部对齐时剪切顶部;除此之外剪切顶部和底部. 垂直方向裁剪 |
clip_horizontal |
Additional option that can be set to have the left and/or right edges of the child clipped to its container’s bounds. The clip is based on the horizontal gravity: a left gravity clips the right edge, a right gravity clips the left edge, and neither clips both edges.
附加选项,用于按照容器的边来剪切对象的左侧和/或右侧的内容. 剪切基于其横向对齐设置:左侧对齐时,剪切右侧;右侧对齐时剪切左侧;除此之外剪切左侧和右侧. 水平方向裁剪 |
简单记忆 : horizontal 都是操作的水平方向,即横向, vertical 都是炒作的垂直方向,即纵向。
对于LinearLayout何时生效的问题
参看:也谈layout_gravity和gravity
http://www.lephone.net/viewthread.php?tid=325
对于 LinearLayout
当 android:orientation="vertical" 时, 只有水平方向的设置才起作用,垂直方向的设置不起作用。即:left,right,center_horizontal 是生效的。
当 android:orientation="horizontal" 时, 只有垂直方向的设置才起作用,水平方向的设置不起作用。即:top,bottom,center_vertical 是生效的。
layout_gravity 和 gravity以及对应值的详解相关推荐
- python列表切片后得到剩余列表_python列表切片和嵌套列表取值操作详解
python列表切片和嵌套列表取值操作详解 给出列表切片的格式: [开头元素::步长] # 输出直到最后一个元素,(最后一个冒号和步长可以省略,下同) [开头元素:结尾元素(不含):步长] # 其中, ...
- python修改xml标签的值_对python修改xml文件的节点值方法详解
这是我的xml文件结构 <?xml version='1.0' encoding='utf-8'?> JPEGImages train_2018-05-08_1000.jpg D:\all ...
- Struts2值栈详解
Struts2值栈详解 基本介绍 ValueStack是Struts2的一个接口,字面意义为值栈,OgnlValueStack是 ValueStack的实现类,客 户端发起一个请求,struts2架构 ...
- (转)C#进阶系列——WebApi 接口返回值不困惑:返回值类型详解
原文链接:https://www.cnblogs.com/landeanfen/p/5501487.html 阅读目录 一.void无返回值 二.IHttpActionResult 1.Json(T ...
- window.open返回值实例详解(子窗口向父窗口回显)
window.open返回值实例详解(子窗口向父窗口回显) window.open实例: 1.父页面: <script language="javascript" type= ...
- C++11 左值、右值、右值引用详解
C++11 左值.右值.右值引用详解 左值.右值 在C++11中所有的值必属于左值.右值两者之一,右值又可以细分为纯右值.将亡值. 在C++11中可以取地址的.有名字的就是左值,反之,不能取地址的.没 ...
- python input与返回值-Python 详解基本语法_函数_返回值
Python 详解基本语法 概要: 函数的返回值是函数重要的组成部分.函数的根本在于实现程序的部分功能,所以很多时候我们需要将函数执行后的结果返回给程序再由程序作出进一步的操作.可以说是函数的返回值令 ...
- python字典修改键所对应值_详解如何修改python中字典的键和值
我们知道python中字典是无序的,它们都是通过hash去对应的.一般的如果我们需要修改字典的值,只需要直接覆盖即可,而修改字典的键,则需要使用字典自带的pop函数,示例如下: t = {} t['a ...
- python3主函数返回值_Python 详解基本语法_函数_返回值
Python 详解基本语法 概要: 函数的返回值是函数重要的组成部分.函数的根本在于实现程序的部分功能,所以很多时候我们需要将函数执行后的结果返回给程序再由程序作出进一步的操作.可以说是函数的返回值令 ...
最新文章
- CVPR2020 | 利用NAS搜索针对对抗攻击的鲁棒神经网络结构
- python对笔记本电脑的要求-Python的用法笔记本
- gradle风格的groovy代码
- week 4 ridge regression
- ITK:将像素缓冲区导入到图像中
- 个人对于架构设计的理解
- Active Directory相关博客
- 时钟在微型计算机中作用,微型计算机系统中的实时时钟
- 微软为 Java 开发者推出 VSCode 安装程序
- windows的libcurl下zlib1.dll问题
- 基于MDC的SOA方案
- java中定时JOB的实现方式
- oracle没有正常启动,Oracledbstart无法正常启动处理办法
- tomcat查看线程数
- 【资源】机器学习 周志华
- 女孩子没有事业就只能痛苦
- latex插入pdf
- 洛谷 P3110 [USACO14DEC]驮运Piggy Back ( spfa) 题解
- HTML-embed标签详解
- Invalid argument during startup: Failed to open the .conf file: redis-window
热门文章
- JeeSite 是什么、概述
- 什么是 TF-IDF 算法?
- 新时期,老师该怎么撑伞?
- 圆为什么规定一定是360度_圆为什么是360度?不一样的趣味知识,让你痴迷数学...
- 【画画】UCF Local Programming Contest 2012(Practice)E. Pete's Pantry
- 国内公募REITs火了 5月31号3多亿亿明天开抢!怎么买?买哪只?10问10答解读来了
- JS逆向——裁判文书网(详细图文步骤)
- linux修改英文设置密码,linux 如何修改passwd的密码 设置密码
- pve远程连接 spcie_剑网3PVE远程输出宏 新版本花间宏分享
- 高一计算机专业班主任工作总结,高一年级第一学期班主任工作总结