Android_layout 布局(二)
昨天学习了layout 布局的线性布局和相对布局。
今天我们学习剩余的三个布局,分别是:
一、帧布局(FrameLayout)
在这个布局中,所有的子元素都不能被指定放置的位置,它们通通放于这块区域的左上角,并且后面的子元素直接覆盖在前面的子元素之上,将前面的子元素部分和全部遮挡。
注:帧布局和线性布局的区别
在大体上的用法等等两者还是很相似的。但是有一点两点的根本区别。
帧布局是有“深度”的,它只追求在这个点上去深入。
线性布局是有“广度”的,它是向外延展的,他就是一个“面”。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" > <TextView
android:id="@+id/textView1"
android:layout_width="300dp"
android:layout_height="300dp"
android:text="1"
android:background="#ff00ff"/> <TextView
android:id="@+id/textView2"
android:layout_width="200dp"
android:layout_height="200dp"
android:text="2"
android:background="#00ffff" /> <TextView
android:id="@+id/textView3"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#ff0000"
android:text="3" /> </FrameLayout>
二、绝对布局(AbsoluteLayout)
1.absoluteLayout 又叫坐标布局,可以直接指定子元素的绝对位置(x,y)
2.由于手机屏幕尺寸差别比较大,使用绝对定位的适应性会比较差,在屏幕的适配上有缺陷
3.子控件的属性
android:layout_x="35dip" 控制当前子类控件的x位置
android:layout_y="35dip" 控制当前子类控件的y位置
注:建议最好不要使用绝对布局,我们手机屏幕大小不同,你用这个型号,这个大小的手机定位好的位置,当你换了个手机尺寸不一样的,就会将你的布局打乱,这样很不好。我在这就不演示了。记住,记住,最好不要使用,不利用开发。
三、表格布局(TableLayout)
表格布局类似于我们html 中的table 元素一样。
我们来看看他的属性。
接下来我们做个简单的表格布局的栗子来认识下这个表格布局。计算器
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*" >
<EditText
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center_vertical|right"
android:layout_weight="1"/>
<TableRow
android:layout_weight="1"> <Button
android:id="@+id/btn7"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="7" /> <Button
android:id="@+id/btn8"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="8" /> <Button
android:id="@+id/btn9"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="9" /> <Button
android:id="@+id/btnchu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="/" />
</TableRow> <TableRow
android:layout_weight="1"> <Button
android:id="@+id/btn4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="4" /> <Button
android:id="@+id/btn5"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="5" /> <Button
android:id="@+id/btn6"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="6" /> <Button
android:id="@+id/btncheng"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="*" />
</TableRow> <TableRow
android:layout_weight="1"> <Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="1" /> <Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="2" /> <Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="3" /> <Button
android:id="@+id/btnjian"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="-" />
</TableRow> <TableRow
android:layout_weight="1"> <Button
android:id="@+id/btn0"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="0" /> <Button
android:id="@+id/btndian"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="." /> <Button
android:id="@+id/btnjia"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="+" /> <Button
android:id="@+id/btndeng"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="=" />
</TableRow> <TableRow
android:layout_weight="1"> <Button
android:id="@+id/clear"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_span="4"
android:text="clear" />
</TableRow> </TableLayout>
效果显示是这样的。
关于android 的 layout 布局,就暂时讲这些,关于这几大布局的属性,大家有空都可以去试试,多练习下布局的排布,综合起来,排布一个页面什么的。属性每个布局中的属性。
今天就先到这,欢迎大家一起学习。
Android_layout 布局(二)的更多相关文章
- 基本CSS布局二
基本CSS布局二------基本页面布局二 /*主面板样式*/ #container { width:100%; margin:0px auto;/*主面板DIV居中*/ } /*顶部面板样式*/ # ...
- Android_layout 布局(一)
今天主要学习了Android 的layout布局. Android layout 布局一般分为五种: LinearLayout (线性布局) :子组件按照垂直或者水平方向来布局. RelativeLa ...
- CSS布局(二) 盒子模型属性
盒子模型的属性 宽高width/height 在CSS中,可以对任何块级元素设置显式高度. 如果指定高度大于显示内容所需高度,多余的高度会产生一个视觉效果,就好像有额外的内边距一样: 如果指定高度小于 ...
- Android的学习第六章(布局二--RelativeLayout)
今天我们来说一下Android布局中的Relativelayout布局(相对布局) 根据英译过来意思是相对布局,很容易理解,这一样布局使用的是元素与元素之间的微调做到布局的 含义:通过元素与元素之间的 ...
- Android开发--布局二
1.Andrid:控件布局(表格布局)TableLayout 有多少个TableRow对象就有多少行, 列数等于最多子控件的TableRow的列数 直接在TableLayout加控件,控件会占据一行 ...
- android菜鸟学习笔记7----android布局(二)
3.FrameLayout:帧布局 如同Flash或者photoshop中图层的概念,在上面的图层遮盖下面的图层,没被遮到的地方仍然显示出来. 右击res/layout,然后在弹出的菜单中选择new, ...
- 从汇编看c++中的虚拟继承及内存布局(二)
下面是c++源码: class Top {//虚基类 public: int i; Top(int ii) { i = ii; } virtual int getTop() { cout <&l ...
- 【ExtJS】FormPanel 布局(二)
周末2天好好学习了下布局,现在都给实现了吧. 5.border布局: Border布局将容器分为五个区域:north.south.east.west和center.除了center区域外,其他区域都需 ...
- 【ALearning】第四章 Android Layout组件布局(二)
前面我们分别介绍和学习了LinearLayout(线性布局).FrameLayout(单帧布局)和AbsoluteLayout(绝对布局).这次我们要进行RelativeLayout(相对布局)和Ta ...
随机推荐
- Async Programming - 1 async-await 糖的本质(1)
这一个系列的文章主要来讲 C# 中的语言特性 async-await 在语言层面的本质,我们都知道 await 是编译器进行了一个 rewrite,然而这个 rewrite 并不是直接 rewrite ...
- JVM之数据类型
1.概述 Java虚拟机的数据类型可分为两大类:原始类型(Primitive Types,也称为基本类型)和引用类型(Reference Types).Java虚拟机用不同的字节码指令来操作不同的数据 ...
- 强大的commons
在此之前对commons包了解的不多,最常用的就是StringUtils.isBlack(str)来取代if(str !=null && str.lenght()>1)的判断,昨 ...
- ipad2 恢复
1.用原装充电线连接电脑,并打开itunes~2.同时按住电源键和home键 10秒左右,直到白苹果画面变成黑屏3.按住home键~但要松开电源键,继续等待~直到ipad出现画面(如图) 4.这时候, ...
- AfxMessageBox和MessageBox区别
如果用MFC的话,请尽量使用afxmessagebox,因为这个全局的对话框最安全,也最方便. 但是在WIN32 SDK的情况下只能使用MESSAGEBOX. MessageBox()是Win3 ...
- C++11引用临时变量的终极解析
工作中遇到一个引用临时变量的问题,经过两天的学习,私以为:不仅弄明白了这个问题,还有些自己的独到见解. 这里使用一个简单的例子来把自己的学习过程和理解献给大家,如果有什么问题请不吝指正. **** ...
- C#利用WIN32实现按键注册
using System.Runtime.InteropServices; using System.Collections.Generic; using System; using System.W ...
- Java中的闪光点:ThreadLocal是线程Thead的局部变量,可替代同步机制的设计,值得学习和研究
线程局部变量ThreadLocal,是Java支持的一种线程安全机制,目的是解决多线程的并发问题. 具体来讲,就是多个线程访问该实例对象的变量时,该实例对象将其存储为键值对的形式,保证各个线程(键)分 ...
- 1219 spring3 项目总结
Spring3 项目总结 列志华 (组长) http://www.cnblogs.com/liezhihua/ 团队guihub https://github.com/LWHTF/OrderingFo ...
- location.hash详解
一.#的涵义 #代表网页中的一个位置.其右面的字符,就是该位置的标识符.比如, http://www.example.com/index.html#print 就代表网页index.html的prin ...