Android(安桌)计算器布局实现

        ——解决整个屏幕方案

引言:

    学完了android布局的几种方式,做了一个android计算器。

我在网上搜索了这方面的资料,发现了布局都有问题,没有充满整个屏幕,只是占了一个部分。

老师的建议是:设置字体的大小是关键。但是在我设置好字体大小问题,解决屏幕问题后,发现字体居然没有居中。在靠着水平线的左边。而后使用android:gravity的这个属性,没有改变。但是后来发现,使用的TableLayout好像没有这个属性,嵌套使用了一个Layout,才解决了这个问题。

    

实现效果如下:

LayOut中的xml文件代码如下:

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="fill_parent"
  3. android:layout_height="fill_parent"
  4. android:orientation="vertical" >
  5.  
  6. <TextView
  7. android:id="@+id/writerinfo"
  8. android:layout_width="fill_parent"
  9. android:layout_height="wrap_content"
  10. android:layout_marginTop="5dp"
  11. android:textSize="@dimen/textviewsize"
  12. android:gravity="center_horizontal"
  13. android:text="@string/writer" />
  14.  
  15. <TextView
  16. android:id="@+id/input"
  17. android:layout_width="fill_parent"
  18. android:layout_height="wrap_content"
  19. android:layout_marginTop="5dp"
  20. android:textSize="@dimen/textviewsize"
  21. android:text="@string/inputhint" />
  22.  
  23. <TextView
  24. android:id="@+id/textView2"
  25. android:layout_width="fill_parent"
  26. android:layout_height="wrap_content"
  27. android:layout_marginTop="5dp"
  28. android:textSize="@dimen/textviewsize"
  29. android:text="@string/resulthint" />
  30.  
  31. <TableLayout
  32. android:layout_width="fill_parent"
  33. android:layout_height="wrap_content"
  34. android:stretchColumns="0,1,2,3"
  35. >
  36.  
  37. <TableRow
  38. android:id="@+id/tableRow1"
  39. android:layout_width="fill_parent"
  40. android:layout_height="wrap_content" >
  41.  
  42. <Button
  43. android:id="@+id/num7"
  44. android:layout_width="fill_parent"
  45. android:layout_height="wrap_content"
  46. android:textSize="@dimen/buttonsize"
  47. android:text="7" />
  48.  
  49. <Button
  50. android:id="@+id/num8"
  51. android:layout_width="fill_parent"
  52. android:layout_height="wrap_content"
  53. android:textSize="@dimen/buttonsize"
  54. android:text="8" />
  55.  
  56. <Button
  57. android:id="@+id/num9"
  58. android:layout_width="fill_parent"
  59. android:layout_height="wrap_content"
  60. android:textSize="@dimen/buttonsize"
  61. android:text="9" />
  62.  
  63. <Button
  64. android:id="@+id/divide"
  65. android:layout_width="fill_parent"
  66. android:layout_height="wrap_content"
  67. android:textSize="@dimen/buttonsize"
  68. android:text="/" />
  69.  
  70. </TableRow>
  71.  
  72. <TableRow
  73. android:id="@+id/tableRow2"
  74. android:layout_width="fill_parent"
  75. android:layout_height="wrap_content" >
  76.  
  77. <Button
  78. android:id="@+id/num4"
  79. android:layout_width="wrap_content"
  80. android:layout_height="wrap_content"
  81. android:textSize="@dimen/buttonsize"
  82. android:text="4" />
  83.  
  84. <Button
  85. android:id="@+id/num5"
  86. android:layout_width="wrap_content"
  87. android:layout_height="wrap_content"
  88. android:textSize="@dimen/buttonsize"
  89. android:text="5" />
  90.  
  91. <Button
  92. android:id="@+id/num6"
  93. android:layout_width="wrap_content"
  94. android:layout_height="wrap_content"
  95. android:textSize="@dimen/buttonsize"
  96. android:text="6" />
  97.  
  98. <Button
  99. android:id="@+id/ride"
  100. android:layout_width="wrap_content"
  101. android:layout_height="wrap_content"
  102. android:textSize="@dimen/buttonsize"
  103. android:text="*" />
  104.  
  105. </TableRow>
  106.  
  107. <TableRow
  108. android:id="@+id/tableRow3"
  109. android:layout_width="fill_parent"
  110. android:layout_height="wrap_content" >
  111.  
  112. <Button
  113. android:id="@+id/num1"
  114. android:layout_width="wrap_content"
  115. android:layout_height="wrap_content"
  116. android:textSize="@dimen/buttonsize"
  117. android:text="1" />
  118.  
  119. <Button
  120. android:id="@+id/num2"
  121. android:layout_width="wrap_content"
  122. android:layout_height="wrap_content"
  123. android:textSize="@dimen/buttonsize"
  124. android:text="2" />
  125.  
  126. <Button
  127. android:id="@+id/button11"
  128. android:layout_width="wrap_content"
  129. android:layout_height="wrap_content"
  130. android:textSize="@dimen/buttonsize"
  131. android:text="3" />
  132.  
  133. <Button
  134. android:id="@+id/sub"
  135. android:layout_width="wrap_content"
  136. android:layout_height="wrap_content"
  137. android:textSize="@dimen/buttonsize"
  138. android:text="-" />
  139.  
  140. </TableRow>
  141.  
  142. <TableRow
  143. android:id="@+id/tableRow4"
  144. android:layout_width="fill_parent"
  145. android:layout_height="wrap_content" >
  146.  
  147. <Button
  148. android:id="@+id/num0"
  149. android:layout_width="wrap_content"
  150. android:layout_height="wrap_content"
  151. android:textSize="@dimen/buttonsize"
  152. android:text="0" />
  153.  
  154. <Button
  155. android:id="@+id/point"
  156. android:layout_width="wrap_content"
  157. android:layout_height="wrap_content"
  158. android:textSize="@dimen/buttonsize"
  159. android:text="." />
  160.  
  161. <Button
  162. android:id="@+id/add"
  163. android:layout_width="wrap_content"
  164. android:layout_height="wrap_content"
  165. android:textSize="@dimen/buttonsize"
  166. android:text="+" />
  167.  
  168. <Button
  169. android:id="@+id/equal"
  170. android:layout_width="wrap_content"
  171. android:layout_height="wrap_content"
  172. android:textSize="@dimen/buttonsize"
  173. android:text="=" />
  174.  
  175. </TableRow>
  176. </TableLayout>
  177. <Button
  178. android:id="@+id/clean"
  179. android:layout_width="fill_parent"
  180. android:layout_height="fill_parent"
  181. android:textSize="@dimen/buttonsize"
  182. android:text="clean" />
  183.  
  184. </LinearLayout>
  1. <dimen name="textviewsize">25sp</dimen>
  2. <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. 【Linux学习】Linux用户管理2—用户配置文件

    Linux用户管理2-用户配置文件 /etc/passwd: 存放系统用户的文件 输入 vi /etc/passwd /etc/shadow: 保存保密文件 /etc/group: 群组文件 输入 v ...

  2. 13.详解oauth2授权码流程

    13.详解oauth2授权码流程 把登陆系统单独独立出来,可以给自己写的微服务用,也可以给第三方的系统调用我们的服务 显式的和隐式的,两种方式,

  3. GIL 已经被杀死了么?

    GIL 已经被杀死了么? 本文原创并首发于公众号[Python猫],未经授权,请勿转载. 原文地址:https://mp.weixin.qq.com/s/8KvQemz0SWq2hw-2aBPv2Q ...

  4. HTML基本标签元素

    HTML:  超文本标记语言(HyperText   Mark-up  Language ) 1.作用:写网页结构  2.HTML不区分大小写,建议小写   3.文件后缀 .html  或者  .ht ...

  5. 阻塞调用ShellExecute函数

    SHELLEXECUTEINFO si;ZeroMemory(&si, sizeof(si));si.cbSize = sizeof(si);si.fMask = SEE_MASK_NOCLO ...

  6. LED与OLED的区别:

    LED与OLED的区别: led和oled的发光原理是一样的,只 不过区别是用的材料不一样led用的是金属材料,而oled用的是有机物材料. OLED不需要背光源,自己本身会发光,是采用发光二极管阵列 ...

  7. unity3d easytouch教程

    http://www.taikr.com/group/6/thread/1987 说一说easytouch的简单使用方法,和移动平台上的rpg游戏一样,我们肯定也不陌生,我们经常玩游戏的时候用的都是虚 ...

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

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

  9. centos 7.3 安装vmtools,解决无法编译共享文件夹模块

    环境说明: vmware 12.5.0 build-4352439 centos 7.3.1611   64位,内核版本:Linux version 3.10.0-514.16.1.el7.x86_6 ...

  10. 快速对接payjs的个人支付接口(收银台模式)

    近期在了解个人支付接口,希望能解决我在微信上支付的问题.找了很多平台对比再三,感觉payjs比较专业,其它多是模仿payjs的东西.同时支持支付宝和微信,由于本人支付宝还没开通(需要有一定流量才给开通 ...