文章目录

        • 常用布局
        • LinearLayout
        • RelativeLayout
        • FrameLayout
        • GridLayout

常用布局

  1. FrameLayout:帧布局
  2. LinearLayout:线性布局
  3. RelativeLayout:相对布局
  4. GridLayout:网格布局
公有属性 说明
layout_width
layout_height
布局宽高
layout_margin
layout_marginTop
layout_marginBottom
layout_marginRight
layout_marginLeft
布局外边距
padding
paddingLeft
paddingTop
paddingRight
paddingBottom
布局内边距
gravity 控制布局内的子控件位置
layout_gravity 当前控件相对于父控件的位置
只用用于LinearLayout和FrameLayout

LinearLayout

特有属性 说明
orientation 布局内控件的排序方式:水平、垂直
layout_weight 将布局的控件按权重比例分配

RelativeLayout

特有属性 说明
layout_alignTop
layout_alignParentLeft
layout_alignParentRight
layout_alignParentBottom
layout_centerInParent
layout_centerHorizontal
layout_centerVertical
当前控件相对于父控件的位置
layout_above
layout_below
layout_toLeftOf
layout_toRightOf
当前控件在x控件的位置
layout_alignLeft
layout_alignTop
layout_alignRight
layout_alignBottom
当前控件与x控件的对齐位置

FrameLayout

只具备公有属性

GridLayout

特有属性 说明
columnCount
rowCount
网格布局最大列数和最大行数
orientation 布局内控件的排列方式
layout_column
layout_row
指定单元格在第几列和第几行
layout_columnSpan
layout_rowSpan
指定单元格占据的列数和行数
layout_gravity 指定单元格在布局中的位置
layout_columnWeight
layout_rowWeight
单元格的列权重和行权重

注意:使用layout_columnSpanlayout_columnSpan时需要使权限属性

<?xml version="1.0" encoding="utf-8"?><GridLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="#e5e6e7"    android:columnCount="4"    android:orientation="horizontal"    android:rowCount="7">    <EditText        android:layout_rowWeight="3"        android:layout_columnSpan="4"        android:layout_columnWeight="2"        android:layout_gravity="fill_horizontal"        android:gravity="right|bottom"        android:hint="输入数据..." />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_rowWeight="1"        android:layout_columnSpan="2"        android:layout_columnWeight="1"        android:layout_margin="1dp"        android:background="#fff"        android:gravity="center"        android:text="清空" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_rowWeight="1"        android:layout_columnSpan="2"        android:layout_columnWeight="1"        android:layout_margin="1dp"        android:background="#fff"        android:gravity="center"        android:text="删除" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_rowWeight="1"        android:layout_columnWeight="1"        android:layout_margin="1dp"        android:background="#fff"        android:gravity="center"        android:text="1" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_rowWeight="1"        android:layout_columnWeight="1"        android:layout_margin="1dp"        android:background="#fff"        android:gravity="center"        android:text="2" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_rowWeight="1"        android:layout_columnWeight="1"        android:layout_margin="1dp"        android:background="#fff"        android:gravity="center"        android:text="3" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_rowWeight="1"        android:layout_columnWeight="1"        android:layout_margin="1dp"        android:background="#fff"        android:gravity="center"        android:text="/" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_rowWeight="1"        android:layout_columnWeight="1"        android:layout_margin="1dp"        android:background="#fff"        android:gravity="center"        android:text="4" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_rowWeight="1"        android:layout_columnWeight="1"        android:layout_margin="1dp"        android:background="#fff"        android:gravity="center"        android:text="5" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_rowWeight="1"        android:layout_columnWeight="1"        android:layout_margin="1dp"        android:background="#fff"        android:gravity="center"        android:text="6" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_rowWeight="1"        android:layout_columnWeight="1"        android:layout_margin="1dp"        android:background="#fff"        android:gravity="center"        android:text="*" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_rowWeight="1"        android:layout_columnWeight="1"        android:layout_margin="1dp"        android:background="#fff"        android:gravity="center"        android:text="7" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_rowWeight="1"        android:layout_columnWeight="1"        android:layout_margin="1dp"        android:background="#fff"        android:gravity="center"        android:text="8" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_rowWeight="1"        android:layout_columnWeight="1"        android:layout_margin="1dp"        android:background="#fff"        android:gravity="center"        android:text="9" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_rowWeight="1"        android:layout_columnWeight="1"        android:layout_margin="1dp"        android:background="#fff"        android:gravity="center"        android:text="-" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_rowWeight="1"        android:layout_columnSpan="2"        android:layout_columnWeight="1"        android:layout_margin="1dp"        android:background="#fff"        android:gravity="center"        android:text="0" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_rowWeight="1"        android:layout_columnWeight="1"        android:layout_margin="1dp"        android:background="#fff"        android:gravity="center"        android:text="." />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_rowSpan="2"        android:layout_rowWeight="1"        android:layout_columnWeight="1"        android:layout_margin="1dp"        android:background="#f5041d"        android:gravity="center"        android:text="+" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_rowWeight="1"        android:layout_columnSpan="3"        android:layout_columnWeight="1"        android:layout_margin="1dp"        android:background="#fff"        android:gravity="center"        android:text="=" /></GridLayout>

更多相关文章

  1. 利用View.inflate加载xml
  2. layout_gravity="bottom" 失效
  3. android installd分析
  4. 安卓巴士Android开发神贴整理
  5. Android布局属性详解
  6. Android实现自定义的 时间日期 控件
  7. Android(安卓)关于WebView的相关属性
  8. android TabWidget 位置
  9. android.inputmethodservice.KeyboardView 自定义键盘 字体大小

随机推荐

  1. mac android 环境
  2. Debug native code using addr2line on A
  3. 安卓开发视屏下载
  4. android 开发中将十六进制 颜色代码 转换
  5. android:Spinner 设置收起以及展开的字体
  6. ListView与Button的共存问题解决(点击事件
  7. 查询通讯录拨号发短信
  8. Android编译系统详解(一)
  9. Android Shell Cmd
  10. 上接系出名门Android(8) - 控件(View)之T