从零開始学android<使用嵌套布局实现计算器界面.十七.>
所谓的嵌套布局就是在一个文件里嵌套多个布局文件
<span style="font-size:18px;"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
……
……
……
</FrameLayout > </LinearLayout></span>
接下来使用嵌套布局来实现一个简单计算器的UI效果
以下是基本构思图
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzYxNjk3Ng==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
使用Xml布局文件设置计算器效果
<span style="font-size:18px;"><?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" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="3"
android:orientation="vertical" > <TextView
android:id="@+id/text2"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginTop="0dp"
android:layout_weight="1"
android:padding="0dp" /> <TextView
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginTop="0dp"
android:layout_weight="2"
android:padding="0dp" />
</LinearLayout> <TableLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" > <TableRow
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="0.2" > <Button
android:id="@+id/left_bracket_button"
android:layout_height="fill_parent"
android:layout_marginBottom="1dp"
android:layout_marginLeft="1dp"
android:layout_weight="0.25"
android:background="#333333"
android:text="("
android:textColor="@android:color/white"
android:textSize="25sp" /> <Button
android:id="@+id/right_bracket_button"
android:layout_height="fill_parent"
android:layout_marginBottom="1dp"
android:layout_marginLeft="1dp"
android:layout_weight="0.25"
android:background="#333333"
android:text=")"
android:textColor="@android:color/white"
android:textSize="25sp" /> <Button
android:id="@+id/divisor_button"
android:layout_height="fill_parent"
android:layout_marginBottom="1dp"
android:layout_marginLeft="1dp"
android:layout_weight="0.25"
android:background="#333333"
android:text="÷"
android:textColor="@android:color/white"
android:textSize="25sp" /> <Button
android:id="@+id/backspace_button"
android:layout_height="fill_parent"
android:layout_marginBottom="1dp"
android:layout_marginLeft="1dp"
android:layout_weight="0.25"
android:background="#ffa500"
android:text="C"
android:textSize="25sp" />
</TableRow> <TableRow
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="0.2" >
<Button
android:id="@+id/seven_button"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="0.25"
android:layout_marginLeft="1dp"
android:layout_marginBottom="1dp"
android:textSize="25sp"
android:background="@android:color/darker_gray"
android:text="7" /> <Button
android:id="@+id/eight_button"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="0.25"
android:layout_marginLeft="1dp"
android:layout_marginBottom="1dp"
android:textSize="25sp"
android:background="@android:color/darker_gray"
android:text="8" /> <Button
android:id="@+id/nine_button"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="0.25"
android:layout_marginLeft="1dp"
android:layout_marginBottom="1dp"
android:textSize="25sp"
android:background="@android:color/darker_gray"
android:text="9" /> <Button
android:id="@+id/product_button"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="0.25"
android:layout_marginLeft="1dp"
android:layout_marginBottom="1dp"
android:background="#333333"
android:textSize="25sp"
android:textColor="@android:color/white"
android:text="×" />
</TableRow> <TableRow
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="0.2" >
<Button
android:id="@+id/four_button"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="0.25"
android:layout_marginLeft="1dp"
android:layout_marginBottom="1dp"
android:textSize="25sp"
android:background="@android:color/darker_gray"
android:text="4" /> <Button
android:id="@+id/five_button"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="0.25"
android:layout_marginLeft="1dp"
android:layout_marginBottom="1dp"
android:textSize="25sp"
android:background="@android:color/darker_gray"
android:text="5" /> <Button
android:id="@+id/six_button"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="0.25"
android:layout_marginLeft="1dp"
android:layout_marginBottom="1dp"
android:textSize="25sp"
android:background="@android:color/darker_gray"
android:text="6" /> <Button
android:id="@+id/minus_button"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="0.25"
android:layout_marginLeft="1dp"
android:layout_marginBottom="1dp"
android:background="#333333"
android:textSize="25sp"
android:textColor="@android:color/white"
android:text="-" />
</TableRow> <TableRow
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="0.2" >
<Button
android:id="@+id/one_button"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="0.25"
android:layout_marginLeft="1dp"
android:layout_marginBottom="1dp"
android:textSize="25sp"
android:background="@android:color/darker_gray"
android:text="1" /> <Button
android:id="@+id/two_button"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="0.25"
android:layout_marginLeft="1dp"
android:layout_marginBottom="1dp"
android:textSize="25sp"
android:background="@android:color/darker_gray"
android:text="2" /> <Button
android:id="@+id/three_button"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="0.25"
android:layout_marginLeft="1dp"
android:layout_marginBottom="1dp"
android:textSize="25sp"
android:background="@android:color/darker_gray"
android:text="3" /> <Button
android:id="@+id/plus_button"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="0.25"
android:layout_marginLeft="1dp"
android:layout_marginBottom="1dp"
android:background="#333333"
android:textSize="25sp"
android:textColor="@android:color/white"
android:text="+" />
</TableRow> <TableRow
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="0.2" >
<Button
android:id="@+id/point_button"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_weight="0.5"
android:layout_marginLeft="1dp"
android:layout_marginBottom="1dp"
android:textSize="40sp"
android:background="@android:color/darker_gray"
android:text="." /> <Button
android:id="@+id/zero_button"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_weight="0.5"
android:layout_marginLeft="1dp"
android:layout_marginBottom="1dp"
android:textSize="25sp"
android:background="@android:color/darker_gray"
android:text="0" /> <Button
android:id="@+id/equal_button"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_weight="3.1"
android:layout_marginLeft="1dp"
android:layout_marginBottom="1dp"
android:textSize="25sp"
android:background="#00CC00"
android:text="=" />
</TableRow>
</TableLayout> </LinearLayout></span>
以下是模拟器效果图
上面的代码中重复用到了
<span style="font-size:18px;"> android:layout_weight=""</span>
要想设置好一个布局就必须了解权重的概念android:layout_weight的真实含义
下节预报:
滚动视图ScrollView
从零開始学android<使用嵌套布局实现计算器界面.十七.>的更多相关文章
- 从零開始学android<RelativeLayout相对布局.十六.>
相对布局管理器指的是參考某一其它控件进行摆放,能够通过控制,将组件摆放在一个指定參考组件的上.下.左.右等位置,这些能够直接通过各个组件提供的属性完毕. 以下介绍一下各个方法的基本使用 No. 属性名 ...
- 从零開始学android<数据存储(1)SharedPreferences属性文件.三十五.>
在android中有五种保存数据的方法.各自是: Shared Preferences Store private primitive data in key-value pairs. 相应属性的键值 ...
- 第13章、布局Layouts之RelativeLayout相对布局(从零開始学Android)
RelativeLayout相对布局 RelativeLayout是一种相对布局,控件的位置是依照相对位置来计算的,后一个控件在什么位置依赖于前一个控件的基本位置,是布局最经常使用,也是最灵活的一种布 ...
- 从零開始学android<SeekBar滑动组件.二十二.>
拖动条能够由用户自己进行手工的调节,比如:当用户须要调整播放器音量或者是电影的播放进度时都会使用到拖动条,SeekBar类的定义结构例如以下所看到的: java.lang.Object ↳ an ...
- 从零開始学android<mediaplayer自带播放器(视频播放).四十九.>
MediaPlayer除了能够对音频播放之外,也能够对视频进行播放,可是假设要播放视频仅仅依靠MediaPlayer还是不够的.还须要编写一个能够用于视频显示的空间,而这块显示空间要求能够高速的进行G ...
- 从零開始学android<TabHost标签组件.二十九.>
TabHost主要特点是能够在一个窗体中显示多组标签栏的内容,在Android系统之中每一个标签栏就称为一个Tab.而包括这多个标签栏的容器就将其称为TabHost.TabHost类的继承结构例如以下 ...
- 从零開始开发Android版2048 (一)初始化界面
自学Android一个月多了,一直在工作之余零零散散地看一些东西.感觉经常使用的东西都有些了解了,可是一開始写代码总会出各种奇葩的问题.感觉还是代码写得太少.这样继续杂乱地学习下去进度也太慢了,并且学 ...
- 从零開始学android<Menu菜单组件.三十.>
在Android系统之中.菜单一共同拥有三类:选项菜单(OptionsMenu).上下文菜单(ContextMenu)和子菜单(SubMenu). 今天我们就用几个样例来分别介绍下菜单的使用 acti ...
- 从零開始学android<ImageSwitcher图片切换组件.二十六.>
ImageSwitcher组件的主要功能是完毕图片的切换显示,比如用户在进行图片浏览的时候.能够通过button点击一张张的切换显示的图片,并且使用ImageSwitcher组件在每次切换的时候也能够 ...
随机推荐
- kafka查看消费数据
一.如何查看 在老版本中,使用kafka-run-class.sh 脚本进行查看.但是对于最新版本,kafka-run-class.sh 已经不能使用,必须使用另外一个脚本才行,它就是kafka-co ...
- java基础学习总结——GUI编程(二)
一.事件监听
- SqlServer 批量备份
-- 实现方式1:使用游标 DECLARE @FileName VARCHAR(200), @CurrentTime VARCHAR(50), @DBName VARCHAR(100), @SQL V ...
- Ubuntu编译gdb-ARM调试环境
参考Qt可用的gdb编译,以及交叉编译gdbserver,以及配置QtCreator远程调试 编译脚本 如下: #!/bin/bash echo -e "\033[32m 正在执行步骤一:检 ...
- 【BZOJ】4292: [PA2015]Równanie
题解 \(f(n)\)的取值范围最多\(9^2 * 18\) 直接枚举判断就好 代码 #include <bits/stdc++.h> #define fi first #define s ...
- 判断js数组/对象是否为空
/** * 判断js数组/对象是否为空 * isPrototypeOf() 验证一个对象是否存在于另一个对象的原型链上.即判断 Object 是否存在于 $obj 的原型链上.js中一切皆对象,也就是 ...
- 应用Mongoose开发MongoDB(1)数据库连接
最近因为项目,接触了MongoDB,因为是分工合作,我负责的部分主要是实现前端对数据库增删查改的需求,因此以下内容只着重于针对不同问题如何进行解决. 整个工程的最终目的是通过mongoose编写数据库 ...
- DJANGO ADMIN 一些有用的设置(转)
DJANGO ADMIN 一些有用的设置 Django自带的后台管理是Django明显特色之一,可以让我们快速便捷管理数据.后台管理可以在各个app的admin.py文件中进行控制.以下是我最近摸 ...
- P2398 GCD SUM
P2398 GCD SUM一开始是憨打表,后来发现打多了,超过代码长度了.缩小之后是30分,和暴力一样.正解是,用f[k]表示gcd为k的一共有多少对.ans=sigma k(1->n) k*f ...
- 关于我学XSS躺过的那些坑
XSS字符编码 在学习编码绕过时由于数量多,类型相似,不太容易记得住,记得全,故做此记录. 0x01 Html标签属性中执行 简单了解: Html标签属性中的XSS问题多属于javascript伪协议 ...