线性布局(LinearLayout)
常用属性:
- id属性
唯一标识
#设置id
android:id="@+id/ll1"
- layout_width,layout_height
设置宽度、高度,有三种形式:
1、match_parent 和父容器匹配
2、wrap_content 包含内容
3、xxdp 自定义大小,单位一般使用pd,字体大小一般使用sp
#设置宽度为匹配父容器
#设置高度为200dp
android:layout_width="match_parent"
android:layout_height="200dp"
- background
设置背景
#设置背景为红色
android:background="#ff0000"
- orientation
设置排列方式,有两种排列方式:
1、vertical 垂直排列
2、horizontal 水平排列
#设置为垂直排列
android:orientation="vertical"
- layout_margin
外边距,设置蓝色块的外边距为60dp,效果如图
- padding
内边距,设置最外层容器内边距为50dp,效果如图
- gravity
内部元素对其方式
center 居中
center_vertical 垂直居中
center_horizontal 水平居中
top 靠上
bottom 靠下
等等
设置蓝色块中的元素居中,如图 - layout_weight
权重,两个view的weight都设置为1,那么这两个view会平分剩下的部分,即减去50dp后剩下的部分平分,所以view1比view2多50dp,如果第一个view的width也为0dp,那么这两个view等分。weight值越大,分到的越多。