LinearLayout 线性布局

  首先我们先认识一下长宽的定义方式:wrap_content 和match_parent (fill_parent)。
wrap_content:根据内容调整长或者宽。
match_parent: 自定填充,填满定义的长或者宽。

布局属性:

(1)android:orientation:
  定义线性布局的排列方式,有两个选项:vertical和horizontal。vertical代表垂直分布,horizontal代表水平分布。默认是horizontal。
Android的五种布局_第1张图片 Android的五种布局_第2张图片
      vertical          horizontal

(2)android:layout_gravity
  定义线性布局中控件的布局方式,有很多选项:top, bottom, left , right, center_vertical, fill_vertical, center_horizontal, fill_horizontal, center, fill , clip_vertical, clip_horizontal , start, end。看英文意思就可以理解排列不布局方式,在此不在赘述。

(3)android:layout_weight
  定义线性布局中通过比例来控制控件的大小。例如:
定义两个按钮,分别占比重1/3和2/3。

    <Button  android:layout_width="wrap_content" android:layout_height="0" android:layout_weight="1"/>    <Button  android:layout_width="wrap_content" android:layout_height="0" android:layout_weight="1"/>

            Android的五种布局_第3张图片
            
            
  定义两个按钮, 分别占比重1/5和2/5。需要在开始 “LinearLayout ”中定义一句:”android:weightSum=”5”“,将布局分为5等分。
  

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:weightSum="5">    <Button  android:layout_width="wrap_content" android:layout_height="0" android:layout_weight="1"/>    <Button  android:layout_width="wrap_content" android:layout_height="0" android:layout_weight="1"/></LinearLayout>

            Android的五种布局_第4张图片
            
(3)android:layout_marginXXX  
  XXX可代表:Bottom,End,Left, Right, Start, Top。分别是距离后面id控件的底部,结束,左面,右面,开始,顶部的距离。(注意距离一般用单位dp表示。)

          Android的五种布局_第5张图片

RelativeLayout 相对布局

布局属性:

(1)android:layout_alignParentXXX
  XXX分别代表:Left Right Bottom Top Start End, 分别代表与父空间的左, 右, 低, 顶, 开始, 结尾对齐。
  
         Android的五种布局_第6张图片

(2)android:layout_centerXXX         
  XXX是指:InParent , Vertical, Horizotial。是相对于父空间的中间的布局。
(3)android:layout_toXXXof和android:layout_above(below) 
  XXX是指:LeftOf,Right。是相对于后面id控件的左右。
  above和below是相对于后面id控件的上下。
(4)android:layout_alginBaseLine   
  基准线对齐。

FrameLayout帧布局

  这种布局使用比较少见。
  是一层一层覆盖的。举例理解:放置了一个和一个文本输入框,可以看到他们是重叠的。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent">    <Button  android:layout_width="wrap_content" android:layout_height="wrap_content" />    <EditText  android:layout_width="match_parent" android:layout_height="wrap_content" /></FrameLayout>

   Android的五种布局_第7张图片

布局属性:

android:visibility
  属性值有三个分别是:visible(可见)、 invisible(不可见)、 gone(去除)

TableLayout 表布局

  用表格的形式来布局。
  在布局中一定会包含<TableRow> </TableRow>。一般很少用到,可能就是登陆界面会使用。

布局属性:

(1)android:stretchColumns=”0” 
  本属性的含义是将表格剩余空间用第一列表格填充完整。“0”代指第一列,当然属性值也可以是“0,1,2”,该属性值得含义是让表格的第1,2,3列共同填充剩余空间。
(2)android:layout_span=”2”   
  该属性的含义是让调用该属性控件在表格中占两行。如果属性值为“3”,则为占三行。
(3)android:shrinkColumns=”0”    
  该属性含义是将第一列中的文字自动调整,以适应空间大小。

AbsoluteLayout绝对布局

  因为该布局是采用坐标的形式来进行布局定位的,布局的dp都是固定的,以至于在不同分辨率的手机上显示的布局大小不同造成差异,一次Android中很少有采用这种布局方式的。

更多相关文章

  1. android 在开发WebView时,去掉网页的标题并设置成自定义的标题
  2. Android RecyclerView 多布局与混排
  3. 2011.06.07——— android 1.6 launcher研究之自定义level-list
  4. Android UI---自定义形状shape
  5. android基础入门布局讲解(2)
  6. Android输入法挤乱布局问题
  7. Android 5.0 Material 自定义Dialog 背景 字体大小颜色 ui组件颜
  8. 2019-08-20 Android 线性布局介绍-LinearLayout
  9. Android clickable 属性问题

随机推荐

  1. Qt for Android之Hello World
  2. Android中获取文件存储位置(内部存储或者
  3. android ndk开发支持64位时遇到undefined
  4. Android gps定位
  5. android studio3.0 NDK编译Error: cannot
  6. android 模拟视角转换
  7. Android的布局优化
  8. 在Android应用中实现Google搜索的例子
  9. Android 禁止屏幕旋转 & 旋转屏幕时保持A
  10. 从源码解析-Android中进程间通信Binder机