第24讲 UI_布局 之帧布局 表格布局 绝对布局
第24讲 UI_布局 之帧布局 表格布局 绝对布局
3.
FrameLayout(帧布局)
帧布局是从屏幕的左上角(0,0)坐标开始布局,多个组件层叠排序,后一个组件总会将前一个组件所覆盖,除非最后一个组件是透明的。
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button1" />
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Button2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button3" />
此布局通常用于软件的初始化页面,启动页面等。
属性名称 |
对应方法 |
说明 |
android:foreground |
setForeground(Drawable) |
设置该帧布局容器的前景图像 |
android:foregroundGravity |
setForegroundGravity(int) |
设置前景图像显示的位置 |
4. TableLayout(表格布局)
TableLayout(表格布局),顾名思义就是像表格一样布局,以行、列的方式布局子组件。TableLayout使用TableRow对象来定义多行。每个TableRow就是一行
<TableRow>
<Button android:text="Button1"/>
<Button android:text="Button2"/>
<Button android:text="Button3"/> </TableRow>
<TableRow>
<Button android:text="Button4"/>
<Button android:text="Button5"/>
<Button android:text="Button6"/> </TableRow>
<TableRow>
<Button android:text="Button7"/>
<Button android:text="Button8"/>
<Button android:text="Button9"/> </TableRow>
TableLayout中也有几个常用属性:
(1) android:shrinkColumns属性:以0为序,当TableRow里面的控件布满布局时,指定列自动延伸以填充可用部分;当TableRow里面的控件还没有布满布局时,shrinkColumns不起作用。
(2) android:strechColumns:以第0行为序,指定列对空白部分进行填充。
(3) android:collapseColumns:以0行为序,隐藏指定的列。
(4) android:layout_column:以0行为序,设置组件显示指定列。
(5) android:layout_span:以第0行为序,设置组件显示占用的列数。
//16个按钮
<Button android:id="@+id/one" android:text="1"/>
<Button android:id="@+id/two" android:text="2"/>
<Button android:id="@+id/three" android:text="3"/>
<Button android:id="@+id/devide" android:text="/"/>
<Button android:id="@+id/four" android:text="4"/>
<Button android:id="@+id/five" android:text="5"/>
<Button android:id="@+id/six" android:text="6"/>
<Button android:id="@+id/multiply" android:text="×"/>
<Button android:id="@+id/seven" android:text="7"/>
<Button android:id="@+id/eight" android:text="8"/>
<Button android:id="@+id/nine" android:text="9"/>
<Button android:id="@+id/minus" android:text="-"/>
<Button android:id="@+id/zero" android:layout_columnSpan="2" android:layout_gravity="fill"android:text="0"/>
<Button android:id="@+id/point" android:text="."/>
<Button android:id="@+id/plus" android:layout_rowSpan="2" android:layout_gravity="fill"android:text="+"/>
<Button android:id="@+id/equal" android:layout_columnSpan="3" android:layout_gravity="fill" android:text="="/>
5. AbsoluteLayout(绝对布局)
AbsoluteLayout(绝对布局),组件的位置可以准确的指定其在屏幕的x/y坐标位置。虽然可以精确的去规定坐标,但是由于代码的书写过于刚硬,使得在不同的设备,不同分辨率的手机移动设备上不能很好的显示应有的效果,所以此布局不推荐使用。
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Button1"
android:layout_x="100dp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button2"
android:layout_y="100dp" />
最新文章
- java内省机制及PropertyUtils使用方法
- freeCAD下载与安装
- python之errno
- c#入门笔记(1)数据类型
- POJ 2299 树状数组+离散化求逆序对
- Dubbo Multicast 注册中心即相关代码实现
- IOS设计模式学习(18)模板方法
- 吃透C#集合~大话目录
- 低头看—SQL视频
- JavaScript之包装对象
- leetcode第35题--Valid Sudoku
- 在阿里云上搭建自己的git服务器
- python数据分析工具包(2)——Numpy(二)
- js、css等引入文件路径正确,却报404的解决办法
- 爬取廖雪峰的python3教程
- VS的ASP.NET项目中cshtml关键词出错 红线,当前上下文中不存在名称
- Does the C standard guarantee buffers are not touched past their null terminator?
- 让一个继承unittest.TestCase的类下的setUp和tearDown只执行一次
- mysql日期格式转换,如何保持原日期?CONVERT/Substring 函数截取。replace替换
- python 如何注释
热门文章
- 一种调用opencv库的C++工程通用的Makefile模板
- KVM硬件辅助虚拟化之 EPT(Extended Page Table)
- iOS中block实现的探究
- CareerCup Chapter 9 Sorting and Searching
- Windows下用Caffe跑自己的数据(遥感影像)
- Dialog( 对话框) 组件
- Beacon浅析
- 在浏览器中就可以写F#程序了,你试试吧
- <;httpProtocol/>;配置http协议头
- nodejs+chromium 创建桌面应用程序