android布局文件部分参数总结
2018-04-12 11:40
246 查看
对刚入手的小白来说,经常把布局文件的一些属性弄混,这里我自己记一下,也供大家参考:
1. android:gravity="center"
android:layout_gravity="center"控件的重心,第一个gravity对应的API为:
Specifies how an object should position its content, on both the
X and Y axes, within its own bounds.
一个布局在自己的界限内应该位于哪些位置,对应于Layout级别的。
第二个layout_gravity对应的API如下:
Standard gravity constant that a child supplies to its parent.
一个控件在它父布局的位置,针对的是button、textview这一类的控件。
有时候定义了layout_gravity,发现并没有按要求显示,我们应该检查一下父布局是否相应的gravity,否则不起作用。
2. android:layout_margin=""
android:padding=""第一个layout_margin对应的API为:
Specifies extra space on the left, top, right and bottom sides of
this view. [dimension]
意思是在四周留下的额外空间,是本控件相对于父控件
第二个padding的API为:
Sets the padding, in pixels, of all four edges. [dimension]
意思是对四周的填充,是针对本控件而言,控件内的内容与控件边界的距离。
3android:layout_toLeftOf=""
Positions the right edge of this view to the left of the given
anchor view ID. [reference]
本控件的右边界在给定ID对应的控件的左边界
第二个layout_alignLeft的API为:
Makes the left edge of this view match the left edge of the given
anchor view ID. [reference]
使本视图的左边界与给定id的视图的左边界视图对齐,其他方向同理
看到有个人总结的挺有道理的一句话:xml参数中含有layout的参数项目为定义的控件相对于parent的关联,没有的一般为本身的定义,以上内容与此相符。也可以说带有layout的与父控件或者给定id的视图相关联,剩下的有时间补。
1. android:gravity="center"
android:layout_gravity="center"控件的重心,第一个gravity对应的API为:
Specifies how an object should position its content, on both the
X and Y axes, within its own bounds.
一个布局在自己的界限内应该位于哪些位置,对应于Layout级别的。
第二个layout_gravity对应的API如下:
Standard gravity constant that a child supplies to its parent.
一个控件在它父布局的位置,针对的是button、textview这一类的控件。
有时候定义了layout_gravity,发现并没有按要求显示,我们应该检查一下父布局是否相应的gravity,否则不起作用。
2. android:layout_margin=""
android:padding=""第一个layout_margin对应的API为:
Specifies extra space on the left, top, right and bottom sides of
this view. [dimension]
意思是在四周留下的额外空间,是本控件相对于父控件
第二个padding的API为:
Sets the padding, in pixels, of all four edges. [dimension]
意思是对四周的填充,是针对本控件而言,控件内的内容与控件边界的距离。
3android:layout_toLeftOf=""
android:layout_alignLeft=""第一个layout_toLeftOfd1API为
Positions the right edge of this view to the left of the given
anchor view ID. [reference]
本控件的右边界在给定ID对应的控件的左边界
第二个layout_alignLeft的API为:
Makes the left edge of this view match the left edge of the given
anchor view ID. [reference]
使本视图的左边界与给定id的视图的左边界视图对齐,其他方向同理
看到有个人总结的挺有道理的一句话:xml参数中含有layout的参数项目为定义的控件相对于parent的关联,没有的一般为本身的定义,以上内容与此相符。也可以说带有layout的与父控件或者给定id的视图相关联,剩下的有时间补。
相关文章推荐
- Android开发的xml布局文件属性总结
- android 布局文件的常用属性总结
- Android开发---xml布局文件中的常见属性总结
- Android 线性布局(LinearLayout)相关官方文档 - 布局参数部分
- Android布局文件中单位的使用总结
- Android开发---xml布局文件中的常见属性总结
- android在布局文件中自定义参数并在初始化时获取
- 【风马一族_Android】代码英语之二 布局文件的Android各个参数
- 2.Android开发---xml布局文件中的常见属性总结
- android自定义Button,通过在XML布局文件里直接使用自定义参数
- Android布局文件绘制原理学习总结 -- measure/layout/draw
- Android开发---xml布局文件中的常见属性总结
- android在布局文件中自定义参数并在初始化时获取
- Android布局文件参数layout_alignTop的作用
- androidUI第二部分---1.2.2Activity对Dialog的管理及Dialog的自定义布局
- android之动画(二)通过动画布局声明文件和关联文件为容器布局----布局动画
- Android横竖屏布局总结
- android tabHost布局之一 不继承TabActivity并以布局文件进行布局
- 原创Android中应用界面布局总结
- Android_布局文件的名称