您的位置:首页 > 移动开发 > Android开发

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=""
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的视图相关联,剩下的有时间补。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: