详解四种基本布局

LinearLayout

  • 线性布局
  • android:orientation=
    • vertical 垂直排列
    • horizontal 水平排列
  • android:layout_gravity= 用于指定文字在控件中的对齐方式
    • top
    • center_vertical
    • bottom

注意若orientation是horizontal,那么控件只能是垂直方向上的对齐 若orientation是vertical,那么控件只能是水平方向上的对齐

  • android:layout_weight 这是一种比例,比如我们有两个控件,都指定了layout_weight=1,那么它们在水平方向上按照1:1的比例平分了水平方向的长度,此时我们指定layout_width多少都无效了

RelativeLayout

  • 相对定位
  • 常见属性alignParentRight,alignParentLeft,centerInParent,alignParentBottom,alignParentTop,layout_above,layout_toLeftOf,layout_below,layout_toRigthOf,layout_alignTop,layout_alignBottom,layout_alignRight和layout_alignLeft

FrameLayout

  • 所有的控件都会摆放在布局的左上角

TableLayout

  • TableRow就是在表中加了一行,没加入一个控件就代表加入了一列,使用layout_span可以进行横跨某几列
  • 在TableRow无法指定控件的宽度,这时候使用android:stretchColumns属性就可以很好的解决这个问题,它允许将TableLayout中的某一列进行拉伸,以达到自动适应屏幕宽度的作用.
  • 指定为数字1就代表如果表格不能占满整个屏幕,那么就将第二列拉伸,如果指定成1,那么就是拉伸第一列
posted on 2021-08-03 00:44  心悦君兮君不知-睿  阅读(107)  评论(0编辑  收藏  举报