《Monkey Android》第8课FrameLayout、GridLayout
来源:互联网 发布:linux 系统软件测试 编辑:程序博客网 时间:2024/05/17 08:10
转发请注明出处:
安卓猴的专栏(http://blog.csdn.net/androidmonkey)
安卓猴的微博(@安卓猴)
通过本节课可以学习到的内容:
FrameLayout的用法
GridLayout的用法
实例代码:
运行效果参见本课程示例App:安卓猴Demos
github地址:https://github.com/git0pen/MonkeyAndroid
FrameLayout
帧布局,在这种布局下,每个添加的子控件都被放在布局的左上角,并覆盖在前一个子控件的上层;此外,FrameLayout中的子控件的位置不能被指定。
GridLayout
自Android4.0版本(API level 14)后,新增的网格布局。
注意:
如果要达到网格的效果,推荐使用LinearLayout来实现,因为使用GridLayout会产生如下问题:
- 不能同时在(x,y)轴方向上进行控件的对齐;
- 当多层布局嵌套的时候会出现性能问题;
- 不能稳定地支持一些支持自由编辑布局的工具。
计算器界面
用GridLayout和Button模仿了一个计算器的按键界面。
布局源码
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <FrameLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" > <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="北京" android:textColor="#898989" android:textSize="18sp" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="上海" android:textColor="#108939" android:textSize="22sp" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="广州" android:textColor="#103339" android:textSize="26sp" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="南京" android:textColor="#efec1c" android:textSize="26sp" /> <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="东莞" android:textColor="#ff5e00" android:textSize="30sp" /> <TextView android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="深圳" android:textColor="#ae00ff" android:textSize="36sp" /> </FrameLayout> <GridLayout android:layout_width="wrap_content" android:layout_height="0dp" android:layout_gravity="center" android:layout_weight="2" android:columnCount="4" android:rowCount="6" > <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="0" android:layout_row="0" android:text="C" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="1" android:layout_row="0" android:text="DEL" /> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="2" android:layout_row="0" android:text="/" /> <Button android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="0" android:layout_row="1" android:text="7" /> <Button android:id="@+id/button6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="1" android:layout_row="1" android:text="8" /> <Button android:id="@+id/button7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="2" android:layout_row="1" android:text="9" /> <Button android:id="@+id/button12" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="3" android:layout_row="1" android:text="-" /> <Button android:id="@+id/button8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="0" android:layout_row="2" android:text="4" /> <Button android:id="@+id/button9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="1" android:layout_row="2" android:text="5" /> <Button android:id="@+id/button10" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="2" android:layout_row="2" android:text="6" /> <Button android:id="@+id/button11" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="3" android:layout_row="0" android:text="*" /> <Button android:id="@+id/button13" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="3" android:layout_row="2" android:text="+" /> <Button android:id="@+id/button15" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="0" android:layout_row="3" android:text="1" /> <Button android:id="@+id/button16" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="1" android:layout_row="3" android:text="2" /> <Button android:id="@+id/button17" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="2" android:layout_row="3" android:text="3" /> <Button android:id="@+id/button14" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="3" android:layout_gravity="fill_vertical" android:layout_row="3" android:layout_rowSpan="2" android:text="=" /> <Button android:id="@+id/button18" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="0" android:layout_columnSpan="2" android:layout_gravity="fill_horizontal" android:layout_row="4" android:text="0" /> <Button android:id="@+id/button19" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="2" android:layout_row="4" android:text="." /> <TextView android:id="@+id/textView7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="0" android:layout_columnSpan="4" android:layout_gravity="fill_horizontal" android:layout_row="5" android:gravity="center" android:text="计算器" android:textColor="#000000" android:textSize="38sp" /> </GridLayout></LinearLayout>
下课
这一节课,我们学习了FrameLayout和GridLayout,它们的使用也需要很多技巧。此外,我们要在平时练习的时候多多敲代码,这样才能熟能生巧。
到这里,所有布局的知识都学习完毕了。接下来,我们就要一起学习各种缤纷的控件了!
关注我,我们一起进步
安卓猴的微博(@安卓猴)
安卓猴的github(@git0pen)
0 0
- 《Monkey Android》第8课FrameLayout、GridLayout
- Android开发 第10课 FrameLayout
- Android用户界面基础之LinearLayout、TableLayout、RelativeLayout、FrameLayout、GridLayout学习
- Android常用布局及属性--FrameLayout、TableLayout、 GridLayout、AbsoluteLayout、RelativeLayout
- RelativeLayout,LinerLayout,GridLayout,FrameLayout随记
- 《Monkey Android》第1课之前言
- 《Monkey Android》第7课RelativeLayout、TableLayout
- 《Monkey Android》第9课Toast土司
- 《Monkey Android》第12课ImageView
- 【Android】六大布局——LinearLayout、RelativeLayout、TableLayout、AbsoluteLayout、FrameLayout、GridLayout
- [Android]笔记8-GridLayout布局
- FrameLayout《第一行代码Android》学习笔记
- FrameLayout AbsoluteLayout GridLayout用法及实例
- android GridLayout。。。
- android gridLayout
- Android--GridLayout
- 《Monkey Android》第2课之环境搭建
- 《Monkey Android》第4课之运行第一个App
- hibernate入门简单案例
- 03 给定链表头结点, 依次输出从尾节点到头结点的数据
- hdu 1358 Period KMP算法
- OkHttpClient
- LeetCode之Tree题目汇总
- 《Monkey Android》第8课FrameLayout、GridLayout
- ZBar大图像处理加速
- 《Monkey Android》第9课Toast土司
- 软件设置安装问题之vs
- android基础学习之六大Layout布局
- android常用控件
- MySQL 免安装配置
- 《Monkey Android》第10课TextView和EditText
- 每天进步一点点——五分钟理解一致性哈希算法(consistent hashing)