Android计算器布局
Android(安桌)计算器布局实现
——解决整个屏幕方案
引言:
学完了android布局的几种方式,做了一个android计算器。
我在网上搜索了这方面的资料,发现了布局都有问题,没有充满整个屏幕,只是占了一个部分。
老师的建议是:设置字体的大小是关键。但是在我设置好字体大小问题,解决屏幕问题后,发现字体居然没有居中。在靠着水平线的左边。而后使用android:gravity的这个属性,没有改变。但是后来发现,使用的TableLayout好像没有这个属性,嵌套使用了一个Layout,才解决了这个问题。
实现效果如下:

LayOut中的xml文件代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <TextView
android:id="@+id/writerinfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textSize="@dimen/textviewsize"
android:gravity="center_horizontal"
android:text="@string/writer" /> <TextView
android:id="@+id/input"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textSize="@dimen/textviewsize"
android:text="@string/inputhint" /> <TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textSize="@dimen/textviewsize"
android:text="@string/resulthint" /> <TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="0,1,2,3"
> <TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" > <Button
android:id="@+id/num7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/buttonsize"
android:text="7" /> <Button
android:id="@+id/num8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/buttonsize"
android:text="8" /> <Button
android:id="@+id/num9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/buttonsize"
android:text="9" /> <Button
android:id="@+id/divide"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/buttonsize"
android:text="/" /> </TableRow> <TableRow
android:id="@+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" > <Button
android:id="@+id/num4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/buttonsize"
android:text="4" /> <Button
android:id="@+id/num5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/buttonsize"
android:text="5" /> <Button
android:id="@+id/num6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/buttonsize"
android:text="6" /> <Button
android:id="@+id/ride"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/buttonsize"
android:text="*" /> </TableRow> <TableRow
android:id="@+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="wrap_content" > <Button
android:id="@+id/num1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/buttonsize"
android:text="1" /> <Button
android:id="@+id/num2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/buttonsize"
android:text="2" /> <Button
android:id="@+id/button11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/buttonsize"
android:text="3" /> <Button
android:id="@+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/buttonsize"
android:text="-" /> </TableRow> <TableRow
android:id="@+id/tableRow4"
android:layout_width="fill_parent"
android:layout_height="wrap_content" > <Button
android:id="@+id/num0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/buttonsize"
android:text="0" /> <Button
android:id="@+id/point"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/buttonsize"
android:text="." /> <Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/buttonsize"
android:text="+" /> <Button
android:id="@+id/equal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/buttonsize"
android:text="=" /> </TableRow>
</TableLayout>
<Button
android:id="@+id/clean"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="@dimen/buttonsize"
android:text="clean" /> </LinearLayout>
<dimen name="textviewsize">25sp</dimen>
<dimen name="buttonsize">45dp</dimen>
注:如果读者在复制时没有铺满整个屏幕,请更改
dimens文件中要添加的两个参数。
Android计算器布局的更多相关文章
- Android计算器简单逻辑实现
Android计算器简单逻辑实现 引言: 我的android计算器的实现方式是:按钮输入一次,就处理一次. 但是如果你学过数据结构(栈),就可以使用表达式解析(前缀,后缀)处理. 而这个方式已经很成熟 ...
- 【腾讯Bugly干货分享】Android动态布局入门及NinePatchChunk解密
本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/57c7ff5d53bbcffd68c64411 作者:黄进——QQ音乐团队 摆脱 ...
- Xamarin.Android之布局文件智能提示问题
一.前言 看到有人问关于xamarin.android的布局没智能提示问题(VS 2015),当然,写布局这东西没提示这是一件相对痛苦的事 ,所以这里就提供一个解决的方案! 二.解决方案 想要智能提示 ...
- android—-线性布局
android五大布局之线性布局. 1.线性布局的特点:各个子元素彼此连接,中间不留空白 而今天我们要讲解的就是第一个布局,LinearLayout(线性布局),我们屏幕适配的使用 用的比较多的就是L ...
- Android基本布局
android基本布局有三种:LinearLayout,RelativeLayout,FrameLayout. 一.LinearLayout 1,这是一种垂直布局(或者水平布局),可以通过下面这一句来 ...
- android layout布局属性
参考:http://blog.csdn.net/msmile_my/article/details/9018775 第一类:属性值 true或者 false android:lay ...
- Android 学习第10课,Android的布局
Android的布局 线性布局
- Android 优化布局层次结构
前面介绍过使用HierarchyViewer和Android lint来优化我们的程序,这一篇算是总结性的,借助一个小例子来说用怎么优化应用布局.这个例子是android官网给出的,作者也当一把翻译. ...
- Android 五大布局
Android 五大布局: FrameLayout(框架布局),LinearLayout (线性布局),AbsoluteLayout(绝对布局),RelativeLayout(相对布局),Table ...
随机推荐
- 【Data Structure & Algorithm】在排序数组中查找和为定值的两个数
在排序数组中查找和为定值的两个数 题目:输入一个已经按升序排序过的数组和一个数字,在数组中查找两个数,使得它们的和正好是输入的那个数字,要求时间复杂度是O(n).如果有多对数字的和等于输入的数字,输出 ...
- Black Box--[优先队列 、最大堆最小堆的应用]
Description Our Black Box represents a primitive database. It can save an integer array and has a sp ...
- SCUTOJ - 362 - CC的族谱 - 树上倍增
https://scut.online/p/362 和LCA差不多,注意开大点不怕浪费. #include<bits/stdc++.h> using namespace std; type ...
- 利用YYLabel 进行图文混排+高度计算
利用YYLabel 进行图文混排+高度计算 1.项目需求: 用一个控件显示图片和文字,并且依据图片和文字动态计算控件的高度. 2.方案: 利用YYLabel控件和属性字符串处理. 注:(在使用YYLa ...
- iOS 中 常用的第三方库
现在对于我们 iOS 开发来说,基本上说不可能不使用第三方轮子啦,毕竟没那么多时间,而且自己造的轮子往往想着成为上图中的最后一个,结果却成了上图中第二个或第一个啦,当然大公司另当别论.下面我从之前用过 ...
- ZOJ3164【背包问题(好题)】
%%%%%%%%%%%%%%%岐爷 这一发从来没写过这么旺盛的背包问题... 想法很多,但是好难执行. 题意: 有N种饼干,1-N 每种最多想买Ki个,ki等于0的话没有上界 对于第i种饼干的权值是E ...
- HDU 1556【线段树区间更新】
这篇lazy讲的很棒: https://www.douban.com/note/273509745/ if(tree[rt].l == l && r == tree[rt].r) 这里 ...
- Git的使用方法与GitHub项目托管方法
Git的安装 Windows上安装Git 访问网址:https://git-for-windows.github.io/ 点击Download下载,下载后双击安装包进行安装,一直"下一步&q ...
- 密码破解工具John the Ripper使用说明
John the Ripper John 包描述 John the Ripper 既功能丰富又运行快速. 它在一个程序中结合了几种破解模式,并且可以根据您的特定需求进行全面地配置(你甚至可以使用支持C ...
- bzoj4300 绝世好题 【dp】By cellur925
题目描述: 给定一个长度为\(n\)的数列\(a\),求\(a\)的子序列\(b\)的最长长度,满足bi&bi-1!=0(\(2<=i<=len\)). 90分做法: 并没有部分分 ...