最近因为有安卓开发的课,加上自己还有一个与安卓有关的大创项目,于是开始自学起了安卓。总得来说,安卓开发还是挺有意思的,如果有对这方面感兴趣的话推荐学习一下哦!

最近刚好老师布置了个作业题,感觉做这个蛮有意思的 。

哈哈,废话少说,直入主题! (⊙v⊙)

这个是效果图

布局

这个是对应的布局xml文件内容

  1. 1 <?xml version="1.0" encoding="utf-8"?>
  2. 2 <TableLayout
  3. 3 xmlns:android="http://schemas.android.com/apk/res/android"
  4. 4 xmlns:app="http://schemas.android.com/apk/res-auto"
  5. 5 xmlns:tools="http://schemas.android.com/tools"
  6. 6 android:layout_width="match_parent"
  7. 7 android:layout_height="match_parent"
  8. 8 android:gravity="center_vertical">
  9. 9
  10. 10 <TextView
  11. 11 android:layout_span="2"
  12. 12 android:layout_width="match_parent"
  13. 13 android:layout_height="100dp"
  14. 14 android:background="@mipmap/backgroundcolor"
  15. 15 android:hint="1000"
  16. 16 android:textSize="80dp"
  17. 17 android:gravity="right"/>
  18. 18 <TextView />
  19. 19 <TableRow
  20. 20 android:layout_marginTop="2dp"
  21. 21 android:layout_width="wrap_content"
  22. 22 android:layout_height="wrap_content"
  23. 23 android:gravity="fill_horizontal">
  24. 24 <Button
  25. 25 android:layout_weight="1"
  26. 26 android:layout_width="wrap_content"
  27. 27 android:layout_height="match_parent"
  28. 28 android:text="ON"/>
  29. 29 <Button
  30. 30 android:layout_weight="1"
  31. 31 android:layout_width="wrap_content"
  32. 32 android:layout_height="match_parent"
  33. 33 android:text="OFF"/>
  34. 34 <Button
  35. 35 android:layout_weight="1"
  36. 36 android:layout_width="wrap_content"
  37. 37 android:layout_height="match_parent"
  38. 38 android:text="M+"/>
  39. 39 <Button
  40. 40 android:layout_weight="1"
  41. 41 android:layout_width="wrap_content"
  42. 42 android:layout_height="match_parent"
  43. 43 android:text="M-"/>
  44. 44 </TableRow>
  45. 45 <TableRow
  46. 46 android:layout_width="wrap_content"
  47. 47 android:layout_height="wrap_content"
  48. 48 android:gravity="fill_horizontal">
  49. 49 <Button
  50. 50 android:layout_weight="1"
  51. 51 android:layout_width="wrap_content"
  52. 52 android:layout_height="match_parent"
  53. 53 android:text="AC"/>
  54. 54 <Button
  55. 55 android:layout_weight="1"
  56. 56 android:layout_width="wrap_content"
  57. 57 android:layout_height="match_parent"
  58. 58 android:text="+/-"/>
  59. 59 <Button
  60. 60 android:layout_weight="1"
  61. 61 android:layout_width="wrap_content"
  62. 62 android:layout_height="match_parent"
  63. 63 android:text="DEL"/>
  64. 64 <Button
  65. 65 android:layout_weight="1"
  66. 66 android:layout_width="wrap_content"
  67. 67 android:layout_height="match_parent"
  68. 68 android:text="%"/>
  69. 69 </TableRow>
  70. 70 <TableRow
  71. 71 android:layout_width="wrap_content"
  72. 72 android:layout_height="wrap_content"
  73. 73 android:gravity="fill_horizontal">
  74. 74 <Button
  75. 75 android:layout_weight="1"
  76. 76 android:layout_width="wrap_content"
  77. 77 android:layout_height="match_parent"
  78. 78 android:text="1"/>
  79. 79 <Button
  80. 80 android:layout_weight="1"
  81. 81 android:layout_width="wrap_content"
  82. 82 android:layout_height="match_parent"
  83. 83 android:text="2"/>
  84. 84 <Button
  85. 85 android:layout_weight="1"
  86. 86 android:layout_width="wrap_content"
  87. 87 android:layout_height="match_parent"
  88. 88 android:text="3"/>
  89. 89 <Button
  90. 90 android:layout_weight="1"
  91. 91 android:layout_width="wrap_content"
  92. 92 android:layout_height="match_parent"
  93. 93 android:text="/"/>
  94. 94 </TableRow>
  95. 95 <TableRow
  96. 96 android:layout_width="wrap_content"
  97. 97 android:layout_height="wrap_content"
  98. 98 android:gravity="fill_horizontal">
  99. 99 <Button
  100. 100 android:layout_weight="1"
  101. 101 android:layout_width="wrap_content"
  102. 102 android:layout_height="match_parent"
  103. 103 android:text="4"/>
  104. 104 <Button
  105. 105 android:layout_weight="1"
  106. 106 android:layout_width="wrap_content"
  107. 107 android:layout_height="match_parent"
  108. 108 android:text="5"/>
  109. 109 <Button
  110. 110 android:layout_weight="1"
  111. 111 android:layout_width="wrap_content"
  112. 112 android:layout_height="match_parent"
  113. 113 android:text="6"/>
  114. 114 <Button
  115. 115 android:layout_weight="1"
  116. 116 android:layout_width="wrap_content"
  117. 117 android:layout_height="match_parent"
  118. 118 android:text="×"/>
  119. 119 </TableRow>
  120. 120 <TableRow
  121. 121 android:layout_width="wrap_content"
  122. 122 android:layout_height="wrap_content"
  123. 123 android:gravity="fill_horizontal">
  124. 124 <Button
  125. 125 android:layout_weight="1"
  126. 126 android:layout_width="wrap_content"
  127. 127 android:layout_height="match_parent"
  128. 128 android:text="7"/>
  129. 129 <Button
  130. 130 android:layout_weight="1"
  131. 131 android:layout_width="wrap_content"
  132. 132 android:layout_height="match_parent"
  133. 133 android:text="8"/>
  134. 134 <Button
  135. 135 android:layout_weight="1"
  136. 136 android:layout_width="wrap_content"
  137. 137 android:layout_height="match_parent"
  138. 138 android:text="9"/>
  139. 139
  140. 140 <Button
  141. 141 android:layout_width="wrap_content"
  142. 142 android:layout_height="match_parent"
  143. 143 android:layout_weight="1"
  144. 144 android:text="-" />
  145. 145 </TableRow>
  146. 146 <TableRow
  147. 147 android:layout_width="wrap_content"
  148. 148 android:layout_height="wrap_content"
  149. 149 android:gravity="fill_horizontal">
  150. 150 <Button
  151. 151 android:layout_weight="1"
  152. 152 android:layout_width="wrap_content"
  153. 153 android:layout_height="match_parent"
  154. 154 android:text="0"/>
  155. 155 <Button
  156. 156 android:layout_weight="1"
  157. 157 android:layout_width="wrap_content"
  158. 158 android:layout_height="match_parent"
  159. 159 android:text="00"/>
  160. 160 <Button
  161. 161 android:layout_weight="1"
  162. 162 android:layout_width="wrap_content"
  163. 163 android:layout_height="match_parent"
  164. 164 android:text="."/>
  165. 165
  166. 166 <Button
  167. 167 android:layout_width="wrap_content"
  168. 168 android:layout_height="match_parent"
  169. 169 android:layout_weight="1"
  170. 170 android:text="+" />
  171. 171 </TableRow>
  172. 172 <Button
  173. 173 android:layout_width="match_parent"
  174. 174 android:layout_height="wrap_content"
  175. 175 android:text="="
  176. 176 android:textSize="30dp"/>
  177. 177 </TableLayout>

另外,为了实现计算器的“显示屏”的效果,我们还需要在res/mipmap里放下我们的Testview的背景图片!(这个可以自己做哦!)

(事情有些多,先给下效果和代码,后面有空就详细说下!^_^)

版权声明:本文为memocean原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/memocean/p/11601986.html