博客
关于我
Android布局——帧布局、表格布局、网格布局
阅读量:581 次
发布时间:2019-03-11

本文共 1278 字,大约阅读时间需要 4 分钟。

帧布局(FrameLayout)

帧布局是一种显示布局方式,允许子元素直接覆盖在前面的子元素之上。一旦添加子控件,子控件会从最后一个已有的子控件开始布局,部分或全部遮盖前面的子控件。

常用属性

  • android:layout_gravity="center":设置控件的重力属性,支持的取值有Gravity的值,如center
  • android:gravity="center":设置控件内容相对于控件本身的位置。
  • android:foreground="@mipmap/bg":设置控件的前景图像。
  • android:foregroundGravity="center_vetical":设置前景图像的重力属性。

案例代码

表格布局(TableLayout)

表格布局可以通过行和列的方式展示控件,适合需要显示大量信息或需要按行排列的布局。

常用属性

  • android:stretchColumns="*":设置可伸展的列,* 代表包括所有列,支持多个列,如"1,2"
  • android:shrinkColumns="1":设置可缩短的列,列索引要明确指定。
  • android:collapseColumns="2,3":隐藏指定的列。

案例代码

网格布局(GridLayout)

网格布局是一种基于行和列的布局方式,其可以自动确定行数和列数。与表格布局不同,网格布局的行和列的交叉点会自动计算,且每个网格的大小是相等的。

常用属性

  • android:orientation="horizontal":设置网格布局的方向,默认为水平方向。
  • android:rowCount="4":设置行数。
  • android:columnCount="3":设置列数。
  • android:layout_rowSpan="2":跨越2行的网格。
  • android:layout_columnSpan="2":跨越2列的网格。
  • android:layout_gravity="fill":填充网格,使其充满父容器。

案例代码

以上是对帧布局、表格布局和网格布局的详细解析,希望对你有所帮助!

转载地址:http://rzytz.baihongyu.com/

你可能感兴趣的文章
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>
NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
查看>>
NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
查看>>
Node JS: < 一> 初识Node JS
查看>>
Node-RED中使用JSON数据建立web网站
查看>>
Node-RED中使用json节点解析JSON数据
查看>>