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计算器布局的更多相关文章

  1. Android计算器简单逻辑实现

    Android计算器简单逻辑实现 引言: 我的android计算器的实现方式是:按钮输入一次,就处理一次. 但是如果你学过数据结构(栈),就可以使用表达式解析(前缀,后缀)处理. 而这个方式已经很成熟 ...

  2. 【腾讯Bugly干货分享】Android动态布局入门及NinePatchChunk解密

    本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/57c7ff5d53bbcffd68c64411 作者:黄进——QQ音乐团队 摆脱 ...

  3. Xamarin.Android之布局文件智能提示问题

    一.前言 看到有人问关于xamarin.android的布局没智能提示问题(VS 2015),当然,写布局这东西没提示这是一件相对痛苦的事 ,所以这里就提供一个解决的方案! 二.解决方案 想要智能提示 ...

  4. android—-线性布局

    android五大布局之线性布局. 1.线性布局的特点:各个子元素彼此连接,中间不留空白 而今天我们要讲解的就是第一个布局,LinearLayout(线性布局),我们屏幕适配的使用 用的比较多的就是L ...

  5. Android基本布局

    android基本布局有三种:LinearLayout,RelativeLayout,FrameLayout. 一.LinearLayout 1,这是一种垂直布局(或者水平布局),可以通过下面这一句来 ...

  6. android layout布局属性

    参考:http://blog.csdn.net/msmile_my/article/details/9018775 第一类:属性值 true或者 false           android:lay ...

  7. Android 学习第10课,Android的布局

    Android的布局 线性布局

  8. Android 优化布局层次结构

    前面介绍过使用HierarchyViewer和Android lint来优化我们的程序,这一篇算是总结性的,借助一个小例子来说用怎么优化应用布局.这个例子是android官网给出的,作者也当一把翻译. ...

  9. Android 五大布局

    Android 五大布局:  FrameLayout(框架布局),LinearLayout (线性布局),AbsoluteLayout(绝对布局),RelativeLayout(相对布局),Table ...

随机推荐

  1. python常用框架及第三方库

    python常用框架及第三方库 一.Web框架 1.Django: 开源web开发框架,它鼓励快速开发,并遵循MVC设计,比较庞大,开发周期短.Django的文档最完善.市场占有率最高.招聘职位最多. ...

  2. 微信小程序开发之真机预览

    1:真机预览时上传组件的坑: 当在真机里面使用上传组件,当进入选择相片或者拍照的时候,小程序会进入后台,调用APP onHide()方法,选择完返回小程序是会调用App Onshow()方法,然后调用 ...

  3. 洛谷 - P1338 - 末日的传说 - 打表

    https://www.luogu.org/problemnew/show/P1338 先打表看了一下规律,居然看出来n的位置是阶梯往前的.而每个阶梯的头头,必有后半段降序. 再仔细看一下居然每次交换 ...

  4. 718. Maximum Length of Repeated Subarray

    Given two integer arrays A and B, return the maximum length of an subarray that appears in both arra ...

  5. lightoj 1027【数学概率】

    #include <bits/stdc++.h> using namespace std; typedef long long LL; const int N=1e2+10; int ma ...

  6. 2016CCPC东北地区大学生程序设计竞赛【01/03/05/06/08】

    吧啦啦啦啦啦啦啦啦啦啦啦能量,ACM,跨!变身!变成一个智障! 04正在酝酿中!!!马上更新!!!!!  01题意:有一个n个点的图,对于任意两个不同的点,他的权值是两个点下标的最小公倍数,求最小生出 ...

  7. hdoj5493【树状数组+二分】

    题意: 给你n个人的高度, 再给出一个值代表该高度下有前面比他高的 或 后面比他高的人数, 求满足条件下的最小字典序, 不行的话输出"impossible" 思路: 对于最小字典序 ...

  8. Elasticsearch and MongoDb

    http://www.linkedin.com/groups/Difference-between-elasticsearch-MongoDB-3393294.S.588764405916973056 ...

  9. 关于pycharm的一个imoprt的随笔

    近来发现pycharm一个方便的地方,from 文件夹名.组件名 import 方法(引入和父级目录同级文件夹下的模块),在pycharm中这种引用是能够成功的,但是在python自带的IDLE中不能 ...

  10. ZSP12项目的总结

    前言:一款测量仪器做出来容易,想好做好还是需要投入更多的时间和心血. 项目概述:硬件已经定型,在C8051F020基础上的软件开发. 一 关于C8051F单片机:虽然自己整过8051单片机,但那已经是 ...