昨天学习了layout 布局的线性布局和相对布局。html
今天咱们学习剩余的三个布局,分别是:android
1、帧布局(FrameLayout)ide
在这个布局中,全部的子元素都不能被指定放置的位置,它们统统放于这块区域的左上角,而且后面的子元素直接覆盖在前面的子元素之上,将前面的子元素部分和所有遮挡。布局
注:帧布局和线性布局的区别学习
在大致上的用法等等二者仍是很类似的。可是有一点两点的根本区别。spa
帧布局是有“深度”的,它只追求在这个点上去深刻。3d
线性布局是有“广度”的,它是向外延展的,他就是一个“面”。code
1 <?xml version="1.0" encoding="utf-8"?> 2 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" > 5 6 <TextView 7 android:id="@+id/textView1" 8 android:layout_width="300dp" 9 android:layout_height="300dp" 10 android:text="1" 11 android:background="#ff00ff"/> 12 13 <TextView 14 android:id="@+id/textView2" 15 android:layout_width="200dp" 16 android:layout_height="200dp" 17 android:text="2" 18 android:background="#00ffff" /> 19 20 <TextView 21 android:id="@+id/textView3" 22 android:layout_width="100dp" 23 android:layout_height="100dp" 24 android:background="#ff0000" 25 android:text="3" /> 26 27 </FrameLayout>
2、绝对布局(AbsoluteLayout)xml
1.absoluteLayout 又叫坐标布局,能够直接指定子元素的绝对位置(x,y)htm
2.因为手机屏幕尺寸差异比较大,使用绝对定位的适应性会比较差,在屏幕的适配上有缺陷
3.子控件的属性
android:layout_x="35dip" 控制当前子类控件的x位置
android:layout_y="35dip" 控制当前子类控件的y位置
注:建议最好不要使用绝对布局,咱们手机屏幕大小不一样,你用这个型号,这个大小的手机定位好的位置,当你换了个手机尺寸不同的,就会将你的布局打乱,这样很很差。我在这就不演示了。记住,记住,最好不要使用,不利用开发。
3、表格布局(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 布局,就暂时讲这些,关于这几大布局的属性,你们有空均可以去试试,多练习下布局的排布,综合起来,排布一个页面什么的。属性每一个布局中的属性。
今天就先到这,欢迎你们一块儿学习。