LinearLayout详解
常见属性
orientation:布局中组件的排列方式,有horizontal(水平)vertical(竖直,默认)
android:orientation="horizontal"//水平
android:orientation="vertical"//竖直,默认
gravity:控制组件所包含的子元素的对齐方式,可以个组合,如(left|buttom)
控制控件内文字的对齐方式
android:gravity="center"//中心
android:gravity="bottom"//底部
layout_gravity:控制该组件在父容器里的对其方式
layout_width:布局的宽度,通过不直接写数字的,用wrap_content (组件实际大小),fill——parent或者match——parent填充满父容器
layout_height:布局的高度,参数同上
id --为该组件设置一个资源id,在java文件中可以通过findViewById(id)找到该组件
background:–为该组件设置应该背景图片或者直接用颜色覆盖
RelativeLayout(相对布局)
核心属性
RelatuveLayout详解
基本属性
gravity --设置容器内组件的对齐反式
ignoreGravity --设置了该属性为true的属性的组件,将不受gravity属性的影响
根据父容器定位
layout_alignParentLeft --左对齐
layout_alignParentRight --右对齐
layout_alignParentTop --顶部对齐
layout_alignParentBottom --底部对齐 true左
android:layout_centerHorizontal – 水平居中
android:layout_centerVeritcal – 垂直居中
android:layout_centerInParent 中间位置
根据兄弟组件定位
layout_toLeftOf – 参考组件的左边
layout_toRightOf --参考组件的右边
layou_above – 参考组件的上方
layout_below–参考组件的下方
layout_alignTop --对齐参考组件的上边界
layout_alignBottom–对齐参考组件的下边界
layout_alignLeft --对齐参考组件的左边界
layout_aliggnRight – 对齐参考组件的右边界
margin(偏移)
设置组件与父容器的边距,又叫偏移
layout_margin --设置组件上下左右的偏移量
layout_marginLeft – 设置组件离左边的偏移量
layout_marginRight --设置组件离右边的偏移量
layuot_marginTop --设置组件离上面的偏移量
layout_marginBoottom – 设置组件离下面的偏移量
padding(填充)
设置组件内容部元素间的边距(比如Textview 里面的字体位置)
android:padding --往内部元素的上下左右填充一定的边距
paddingleft – 往内部的元素的左边填充一定边距
paddingRinght–往内部的元素的右边填充一定边距
paddingtop–往内部的元素的上边填充一定边距
paddingBottom–往内部的元素的下边填充一定边距
属性参数--
bottom--底部//center--中心//fill---填满//left--左方//right--右方//
center_vertical--中心垂直居中//center_horizontal--中心水平居中 //
clip_hortical--裁剪子元素的下边界//clip_vertical--裁剪子元素的上边界//
end--末尾//start--开始部分//top--顶部//center--中心//
fill_vertical--增加对象的竖向大小//fill_horizontal--增加对象的横向大小//