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. monkey之monkeyServer

    基本命令: adb shell monkey --port 1080 & adb forward tcp:1080 tcp:1080 telnet 127.0.0.1 1080 启动andro ...

  2. mysql 三存储引擎

    一 什么是存储引擎 mysql中建立的库===>文件夹 库中建立的表===>文件 现实生活中我们用来存储数据的文件有不同的类型,每种文件类型对应各自不同的处理机制:比如处理文本用txt类型 ...

  3. sql #与$的区别

    #将传入的数据都当成一个字符串,会对自动传入的数据加一个双引号.如:order by #user_id#,如果传入的值是111,那么解析成sql时的值为order by “111”, 如果传入的值是i ...

  4. Spring Boot 创建自定义的properties文件

    以IDEA2018为例,在资源文件夹上点击鼠标右键,依次选择 New -> Resource Bundle ,如下图: 在弹出的对话框中,填写properties文件的名称(不用填写.prope ...

  5. android摄像头获取图像——第一弹

    http://www.cnblogs.com/mengyan/archive/2012/09/01/2666636.html 安卓读取视频的几种方式: 详细讲述请参考网址:http://www.cnb ...

  6. Matplotlib 如何显示中文

    Python 3.x 主要是如下代码 import os font = FontProperties(fname=os.path.expandvars(r"%windir%\fonts\si ...

  7. 记录下java的个人测试方法

    IDEA,用 JUnitGenerator V2.​ 0 做单元测试.. 如果是 SpringBoot,测试类上面加注解 @RunWith(SpringJUnit4ClassRunner.class) ...

  8. 调用Web API将文件上传到服务器的方法(.Net Core)

    最近遇到一个将Excel通过Web API存到服务器的问题,其中涉及到Excel的读取.调用API.Web  API怎么进行接收. 一. Excel的读取.调用API Excel读取以及调用API的代 ...

  9. 用shell脚本监控MySQL主从同步

    企业面试题1:(生产实战案例):监控MySQL主从同步是否异常,如果异常,则发送短信或者邮件给管理员.提示:如果没主从同步环境,可以用下面文本放到文件里读取来模拟:阶段1:开发一个守护进程脚本每30秒 ...

  10. 了解cookie

    1.cookie数据会自动在Web浏览器和Web服务器之间传输的,因此服务端脚本就可以读,写存储在客户端的cookie值. 2.在javascript中使用cookie不会采用任何加密机制,因此是不安 ...