从零開始学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组件在每次切换的时候也能够 ...
随机推荐
- 深入理解java虚拟机-00
这本书买了有两年了,只有买回来翻了两页...今天电脑有点卡,游戏玩不了了,就来看看这本书. 首先看了序言,这本书是第二版,讲解的jdk版本是1.7,现在公司用的1.8,而且1.8的改动也挺大的,不过在 ...
- CF1006C 【Three Parts of the Array】
二分查找水题 记$sum[i]$为$d[i]$的前缀和数组 枚举第一段区间的结尾$i$ 然后二分出$lower$_$bound(sum[n]-sum[i])$的位置$x$,如果$sum[x]$与$su ...
- 浅谈SpringMVC
M--模型(实体vo[视图对象]与页面对面) V--视图(JSP,,velocity,FreeMarker,html,thymeleaf) C--控制器(servlet,if语句控制M数据跳转到V进行 ...
- js里size和length的区别
length: length是js的原生方法,用于获取元素的个数和对象的长度 var length = $(obj).length; size(): size()属于方法,只能作用于对象上,获取元素的 ...
- Docker 简介与shell操作使用
一.Docker概述 1.Docker简介 Docker是一个开源的应用容器引擎:是一个轻量级容器技术:Docker支持将软件编译成一个镜像:然后在镜像中各种软件做好配置,将镜像发布出去 ...
- 程序设计实习MOOC / 程序设计与算法(三)第二周测验
6. 学生信息处理程序 总时间限制: 1000ms 内存限制: 1024kB 描述 实现一个学生信息处理程序,计算一个学生的四年平均成绩. 要求实现一个代表学生的类,并且类中所有成员变量都是[私有的] ...
- Mvc+Dapper+存储过程分页10万条数据
10万条数据采用存储过程分页实现(Mvc+Dapper+存储过程) 有时候大数据量进行查询操作的时候,查询速度很大强度上可以影响用户体验,因此自己简单写了一个demo,简单总结记录一下: 技术:Mvc ...
- 015 jquery中包裹节点
1.介绍 2.程序 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...
- Thinkphp分布式数据库连接代码分析
Thinkphp作为国内的一款流行框架,相信使用的人一定不在少数.本篇我们来分析一下Thinkphp中比较重要的一部分——分布式数据库的连接. 当然了,我们在这里不是去将如何使用模型去对数据库进行增删 ...
- [Luogu5241]序列(DP)
固定一种构造方法,使它能够构造出所有可能的序列. 对于一个要构造的序列,把所有点排成一串,若a[i]=a[i-1],那么从1所在弱连通块往连通块后一个点连,若所有点都在一个连通块里了,就在1所在强连通 ...