AS中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 是生效的。
AS中layout_gravity与gravity的区别的更多相关文章
- Android中layout_gravity和gravity的区别
安卓中的 layout_gravity 属性和 gravity属性 有啥区别? LinearLayout有两个非常相似的属性: android:gravity与android:layout_gravi ...
- Android中的layout_gravity和gravity的区别
在Android的布局中,除了padding和margin容易弄混之外,还有layout_gravity和gravity.按照字面意思来说,layout_gravity就是相对于layout来设置的. ...
- android:layout_gravity和gravity的区别
文章转自http://blog.csdn.net/shakespeare001/article/details/784346,给出了很详细的解释. 1.首先来看看Android:layout_grav ...
- android 布局中 layout_gravity、gravity、orientation、layout_weight【转】
线性布局中,有 4 个及其重要的参数,直接决定元素的布局和位置,这四个参数是 android:layout_gravity ( 是本元素相对于父元素的重力方向 ) android:gravity (是 ...
- 从零开始学android开发-布局中 layout_gravity、gravity、orientation、layout_weight
线性布局中,有 4 个及其重要的参数,直接决定元素的布局和位置,这四个参数是 android:layout_gravity ( 是本元素相对于父元素的重力方向 ) android:gravity (是 ...
- layout_gravity与gravity的区别
1:android:gravity 这个是针对控件里的元素来说的,用来控制元素在该控件里的显示位置. 2:android:layout_gravity 这个是针对控件本身而言,用来控制该控件在包含该控 ...
- layout_gravity和gravity的区别
受不了了,用一遍查一遍...根本记不住,来这里记录一下 layout_gravity是子view相对于父view的位置,比如说,在button中设置了layout_gravity="cent ...
- android 布局中 layout_gravity、gravity、orientation、layout_weight
线性布局中,有 4 个及其重要的参数,直接决定元素的布局和位置,这四个参数是 android:layout_gravity ( 是本元素相对于父元素的重力方向 ) android:gravity (是 ...
- layout_gravity与gravity的区别,和padding margin的区别
https://blog.csdn.net/github_39688629/article/details/77790541
随机推荐
- hdu 1978 How many ways 记忆化搜索+DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1978 思路很好想: 定义f[i][j]表示从点(i,j)出发到达(n,m)的方法数: 那么对于一切从( ...
- ThreadLocal源码解析
主要用途 1)设计线程安全的类 2)存储无需共享的线程信息 设计思路 ThreadLocalMap原理 1)对象存储位置-->当前线程的ThreadLocalMap ThreadLocalMap ...
- Gulp文档入门的文档
Gulp自动化执行文件的操作 首先gulp基于node开发的,先按照node.js,使用npm sudo npm install -g gulp (在全局的范围安装 gulp) gulp --help ...
- 大数的加法运算,杭电oj-1002
原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=1002 [Problem Description] I have a very simple pro ...
- thinkphp中的钩子_什么是钩子?
讲到插件,不得不讲钩子.首先,我们之前说明了插件是一个扩展的功能实现. 既然是扩展的,那么就要很灵活.可复用,并不是像我们之前开发项目,一个功能实现了,就写死在代码里了. 项目其他地方要用了,怎么办, ...
- WCF(远程服务器返回错误: 400 错误的请求)
类似相关问题有以下: WCF- restful接口 POST方式调用报错(远程服务器返回错误: 400 错误的请求) WCF Rest:不使用UriTemplate使用post方式传参解决HTTP40 ...
- web前端面试题记录
记录了2017年5月下旬刚毕业时面试的经典面试题 布局方面 1. 响应式布局,左侧栏目固定,右侧内容随着屏幕宽度变化而变化(高频) flex布局 position布局 css3计算宽度 float布局 ...
- 从Thread,ThreadPool,Task, 到async await 的基本使用方法解读
记得很久以前的一个面试场景: 面试官:说说你对JavaScript闭包的理解吧? 我:嗯,平时都是前端工程师在写JS,我们一般只管写后端代码. 面试官:你是后端程序员啊,好吧,那问问你多线程编程的问题 ...
- mysqldump命令详解
1.数据备份的重要性: 保护公司的数据 网站的7x24提供服务 2.MySQL数据库备份: --all-databases , -A 导出全部数据库. mysqldump -uroot -p --al ...
- 几个页面loading样式
随手练习了几个loading样式,以后看到有意思的loading样式也会补充上.样式的兼容性建议还是去w3c上看下属性的兼容性,至少我习惯这么多,当然,w3c中文网貌似很久很久没更新过了,可能更好的还 ...