从零開始学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组件在每次切换的时候也能够 ...
随机推荐
- 5 个 Laravel Eloquent 小技巧
1. 快速生成 Model & Migration 这并不是一个很多人知道的小技巧,为文章生成 Model 和 Migration. $ php artisan make:migration ...
- springMVC源码分析--视图View(一)
之前的博客springMVC源码分析--HttpMessageConverter数据转化(一)中我们已经介绍了数据返回值的处理,在博客springMVC源码分析--ViewResolver视图解析器( ...
- redis实现分布式锁服务
译自Redis官方文档 在多线程共享临界资源的场景下,分布式锁是一种非常重要的组件.许多库使用不同的方式使用redis实现一个分布式锁管理.其中有一部分简单的实现方式可靠性不足,可以通过一些简单的修改 ...
- 慢查询日志和profiling
MySQL调优三步: 慢查询 (分析出现出问题的sql) Explain (显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句) Profile ...
- 原 nc在centos7上的安装和简单使用
https://blog.csdn.net/qq_16414307/article/details/50291341 https://www.cnblogs.com/rocky-AGE-24/p/69 ...
- 图学ES6-5.正则的扩展
- 【LOJ】#2526. 「HAOI2018」苹果树
题解 这计数题多水啊我怎么调了那么久啊 我不想老年化啊QAQ (注意这里的二叉树带标号) 考虑\(g[i]\)表示\(i\)个点二叉树所有节点的深度和,\(f[i]\)表示\(i\)个点的二叉树两两节 ...
- git仓库使用
1.git命令参数 usage: git [--version] [--help] [-c name=value] [--exec-path[=<path>]] [--html-path] ...
- python文件相关操作
Python文件相关操作 打开文件 打开文件,采用open方法,会将文件的句柄返回,如下: f = open('test_file.txt','r',encoding='utf-8') 在上面的代码中 ...
- BZOJ 3253 Fence Repair 哈夫曼树 水题
http://poj.org/problem?id=3253 这道题约等于合并果子,但是通过这道题能够看出来哈夫曼树是什么了. #include<cstdio> #include<c ...