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. 3.11-3.14 Hive 企业使用优化2

    一.查看HQL执行计划explain 1.explain hive在执行的时候会把所对应的SQL语句都会转换成mapreduce代码执行,但是具体的MR执行信息我们怎样才能看出来呢? 这里就用到了ex ...

  2. C#基础之--线程、任务和同步:一、异步委托

    创建线程的一种简单方式是定义一个委托,并异步调用它.委托是方法的类型安全的引用. Delegate还支持异步地调用方法.在后台Delegate类会创建一个执行任务的线程. 为了说明委托的异步特性,从一 ...

  3. 带着问题看 react-redux 源码实现

    前言 Redux作为通用的状态管理器,可以搭配任意界面框架.所以并搭配react使用的话就要借助redux官方提供的React绑定库react-redux,以高效灵活的在react中使用redux.下 ...

  4. JDK 重要目录结构

    \bin 目录包含 Java 的开发工具,包括 Java 编译器 javac.exe.Java 解释器 java.exe 等: javac:Java 编译器,用来将 Java 程序编译成字节码 jav ...

  5. springcloud2 (三) 服务治理Eureka及其实现原理

    代码地址:https://gitlab.com/showkawa/architect/tree/master/microservice/eurake 基于springcloud2分析eurake知识点 ...

  6. js监听键盘提交表单

    <!DOCTYPE html> <html> <head> <title>登陆系统</title> <link href=" ...

  7. 5 天 4000 star 的一个爆款开源项目

    今天早上起来浏览 GitHub 的时候,在周热门趋势排行榜上看到了这么一个开源项目,仅仅 5 天时间,爬到了周排行榜的第一名的位置.而在每天的排行榜上,今天一早也高高位居排行榜的第二位. 这个开源项目 ...

  8. JAVA 7新特性——在单个catch代码块中捕获多个异常,以及用升级版的类型检查重新抛出异常

    在Java 7中,catch代码块得到了升级,用以在单个catch块中处理多个异常.如果你要捕获多个异常并且它们包含相似的代码,使用这一特性将会减少代码重复度.下面用一个例子来理解. Java 7之前 ...

  9. 关于java和python同时使用rabbitmq时队列同名问题的探讨

    问题引出: 我们知道,进程之间是不能直接通信的,但是今天学习rabbitmq时发现一个奇怪的问题,即当我开启rabbitmq,用java写好的代码给rabbitmq发送完消息后并没有急着使用java去 ...

  10. SOA思想

    参考:https://www.cnblogs.com/renzhitian/p/6853289.html 是什么 SOA service-oriented architecture 面向服务的体系结构 ...