第一类:属性值为true或false

android:layout_centerHrizontal 水平居中

android:layout_centerVertical 垂直居中

android:layout_centerInparent 相对于父元素完全居中

android:layout_alignParentBottom 贴紧父元素的下边缘

android:layout_alignParentLeft 贴紧父元素的左边缘

android:layout_alignParentRight 贴紧父元素的右边缘

android:layout_alignParentTop 贴紧父元素的上边缘

android:layout_alignWithParentIfMissing 如果对应的兄弟元素找不到的话就以父元素做参照物

第二类:属性值必须为id的引用名“@id/id-name”

android:layout_below 在某元素的下方

android:layout_above 在某元素的的上方

android:layout_toLeftOf 在某元素的左边

android:layout_toRightOf 在某元素的右边

android:layout_alignTop 本元素的上边缘和某元素的的上边缘对齐

android:layout_alignLeft 本元素的左边缘和某元素的的左边缘对齐

android:layout_alignBottom 本元素的下边缘和某元素的的下边缘对齐

android:layout_alignRight 本元素的右边缘和某元素的的右边缘对齐

第三类:属性值为具体的像素值,如30dip,40px

android:layout_marginBottom 离某元素底边缘的距离

android:layout_marginLeft 离某元素左边缘的距离

android:layout_marginRight 离某元素右边缘的距离

android:layout_marginTop 离某元素上边缘的距离

android:gravity 

android:gravity属性是对该view 内容的限定.比如一个button 上面的text. 你可以设置该text 在view的靠左,靠右等位置.以button为例,android:gravity="right"则button上面的文字靠右

android:layout_gravity

android:layout_gravity是用来设置该view相对与起父view 的位置.比如一个button 在linearlayout里,你想把该button放在靠左、靠右等位置就可以通过该属性设置.以button为例,android:layout_gravity="right"则button靠右

android:layout_alignParentRight

使当前控件的右端和父控件的右端对齐。这里属性值只能为true或false,默认false。

padding和margin的区别:

google的Android文档里的解释:

public static final int padding

Since: API Level 1

Sets the padding, in pixels, of all four edges. Padding is defined as space between the edges of the view and the view's content. A views size will include it's padding. If a background is provided, the padding will initially be set to that (0 if the drawable does not have padding). Explicitly setting a padding value will override the corresponding padding found in the background.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

Constant Value: 16842965 (0x010100d5)

再看margin,以marginBottom 举例

Android:layout_marginBottom

Since: API Level

Specifies extra space on the bottom side of this view. This space is outside this view's bounds.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol layout_marginBottom.

Related Methods

setMargins(int,int,int,int)

所以padding是定义控件自己的内容和控件边缘之间的距离,padding有填充填料的意思,而margin是在说控件的四个边缘之外的距离,指的是和别的控件之间的距离,margin有边缘,页面留白的意思

借用一幅别人的图来说明

感觉android:gravity,android:padding是相对于空间自身而言的,而android:layout_gravity,android:layout_margin是控件相对于父控件或者是其他控件的,ndroid:layout_gravity是当前控件相对于父控件而android:margin当前控件四个边缘的距离,可以是父控件也可以是其他控件。

Weight:对应的设置为android:layout_weight。layout_weight 用于给一个线性布局中的诸多视图的重要度赋值。所有的视图都有一个layout_weight值,默认为零,意思是需要显示多大的视图就占据多大的屏幕空间。若赋一个高于零的值,则将父视图中的可用空间分割,分割大小具体取决于每一个视图的layout_weight值以及该值在当前屏幕布局的整体 layout_weight值和在其它视图屏幕布局的layout_weight值中所占的比率而定。举个例子:比如说我们在水平方向上有一个文本标签和两个文本编辑元素。该文本标签并无指定layout_weight值,所以它将占据需要提供的最少空间。如果两个文本编辑元素每一个的 layout_weight值都设置为1,则两者平分在父视图布局剩余的宽度(因为我们声明这两者的重要度相等)。如果两个文本编辑元素其中第一个的 layout_weight值设置为1,而第二个的设置为2,则剩余空间的三分之二分给第一个,三分之一分给第二个(数值越小,重要度越高)。但是对于LinearLayout之间则以反比的形式显示在屏幕上(即数值越小,重要度越小)

更多相关文章

  1. Android中有关布局的几个问题
  2. Android高级--自定义控件一,优酷…
  3. Android中有关布局的几个问题
  4. Android四大布局及其主要属性
  5. Android四大布局及其主要属性
  6. Android(安卓)相对布局
  7. RelativeLayout布局中控件常用布局属性
  8. android 开发中遇到的问题汇总
  9. 自定义动画(animation)时set中的各元素效果

随机推荐

  1. Android权限管理
  2. Android硬件抽象层(HAL)概要介绍和学习计划
  3. Android(安卓)Jetpack :Navigation 学习笔
  4. android:configChanges属性在不同版本SDK
  5. Android(安卓)Broadcast receiver使用入
  6. Android架构分析之Android智能指针(二)
  7. Android(安卓)Studio 插件--SelectorChap
  8. Android中String资源文件的format方法
  9. 一篇文章看明白 Android(安卓)图形系统 S
  10. Android应用开发中的风格和主题(style,th