今天初步学习了如何通过Android Studio开发简单的程序,并通过在网上寻找代码,成功的修改并写出了一个计算器的小程序。但是通过本次的学习我只是简单掌握了如何通过android studio设计出简单程序的界面,至于程序后台的运算,判断存储仍毫无头绪,并且没有学会如何添加背景图片的操作,这些是我在往后的学习中必需掌握的东西,希望通过明天的学习我能够初步的掌握后台的操作,争取早日能够完成第一次各人作业程序的开发。

计算器程序运行和设计界面:

界面设计部分代码:

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  3     android:layout_width="fill_parent"
  4     android:layout_height="wrap_content"
  5     >
  6     <LinearLayout
  7         android:layout_width="fill_parent"
  8         android:layout_height="fill_parent"
  9         android:orientation="vertical" >
 10         <EditText
 11             android:id="@+id/input"
 12             android:layout_width="fill_parent"
 13             android:layout_height="wrap_content"
 14             android:layout_gravity="center"
 15             android:editable="false"
 16             android:hint="@string/shuru" />
 17 
 18         <EditText
 19             android:id="@+id/output"
 20             android:layout_width="fill_parent"
 21             android:layout_height="wrap_content"
 22             android:layout_gravity="center"
 23             android:editable="true"
 24             android:gravity="right"
 25             android:hint="@string/shuchu" />
 26 
 27         <RelativeLayout
 28             android:layout_width="fill_parent"
 29             android:layout_height="wrap_content" >
 30 
 31             <Button
 32                 android:id="@+id/seven"
 33                 android:layout_width="80dp"
 34                 android:layout_height="70dp"
 35                 android:layout_alignParentLeft="true"
 36                 android:text="@string/seven"
 37                 android:textSize="40sp" />
 38 
 39             <Button
 40                 android:id="@+id/eight"
 41                 android:layout_width="80dp"
 42                 android:layout_height="70dp"
 43                 android:layout_toRightOf="@id/seven"
 44                 android:text="@string/eight"
 45                 android:textSize="40sp" />
 46 
 47             <Button
 48                 android:id="@+id/nine"
 49                 android:layout_width="80dp"
 50                 android:layout_height="70dp"
 51                 android:layout_toRightOf="@id/eight"
 52                 android:text="@string/nine"
 53                 android:textSize="40sp" />
 54 
 55             <Button
 56                 android:id="@+id/add"
 57                 android:layout_width="80dp"
 58                 android:layout_height="70dp"
 59                 android:layout_alignParentRight="true"
 60                 android:layout_toRightOf="@id/nine"
 61                 android:text="@string/add"
 62                 android:textSize="40sp" />
 63 
 64             <Button
 65                 android:id="@+id/four"
 66                 android:layout_width="80dp"
 67                 android:layout_height="70dp"
 68                 android:layout_alignParentLeft="true"
 69                 android:layout_below="@id/seven"
 70                 android:text="@string/four"
 71                 android:textSize="40sp" />
 72 
 73             <Button
 74                 android:id="@+id/five"
 75                 android:layout_width="80dp"
 76                 android:layout_height="70dp"
 77                 android:layout_below="@id/eight"
 78                 android:layout_toRightOf="@id/four"
 79                 android:text="@string/five"
 80                 android:textSize="40sp" />
 81 
 82             <Button
 83                 android:id="@+id/six"
 84                 android:layout_width="80dp"
 85                 android:layout_height="70dp"
 86                 android:layout_below="@id/nine"
 87                 android:layout_toRightOf="@id/five"
 88                 android:text="@string/six"
 89                 android:textSize="40sp" />
 90 
 91             <Button
 92                 android:id="@+id/subtract"
 93                 android:layout_width="80dp"
 94                 android:layout_height="70dp"
 95                 android:layout_alignParentRight="true"
 96                 android:layout_below="@id/add"
 97                 android:layout_toRightOf="@id/six"
 98                 android:text="@string/subtract"
 99                 android:textSize="40sp" />
100 
101             <Button
102                 android:id="@+id/one"
103                 android:layout_width="80dp"
104                 android:layout_height="70dp"
105                 android:layout_alignParentLeft="true"
106                 android:layout_below="@id/four"
107                 android:text="@string/one"
108                 android:textSize="40sp" />
109 
110             <Button
111                 android:id="@+id/two"
112                 android:layout_width="80dp"
113                 android:layout_height="70dp"
114                 android:layout_below="@id/five"
115                 android:layout_toRightOf="@id/one"
116                 android:text="@string/two"
117                 android:textSize="40sp" />
118 
119             <Button
120                 android:id="@+id/three"
121                 android:layout_width="80dp"
122                 android:layout_height="70dp"
123                 android:layout_below="@id/six"
124                 android:layout_toRightOf="@id/two"
125                 android:text="@string/three"
126                 android:textSize="40sp" />
127 
128             <Button
129                 android:id="@+id/multiply"
130                 android:layout_width="80dp"
131                 android:layout_height="70dp"
132                 android:layout_alignParentRight="true"
133                 android:layout_below="@id/subtract"
134                 android:layout_toRightOf="@id/three"
135                 android:text="@string/multiply"
136                 android:textSize="40sp" />
137 
138             <Button
139                 android:id="@+id/zero"
140                 android:layout_width="80dp"
141                 android:layout_height="70dp"
142                 android:layout_alignParentLeft="true"
143                 android:layout_below="@id/one"
144                 android:text="@string/zero"
145                 android:textSize="40sp" />
146 
147             <Button
148                 android:id="@+id/clear"
149                 android:layout_width="80dp"
150                 android:layout_height="70dp"
151                 android:layout_below="@id/two"
152                 android:layout_toRightOf="@id/zero"
153                 android:text="@string/clear"
154                 android:textSize="40sp" />
155 
156             <Button
157                 android:id="@+id/result"
158                 android:layout_width="80dp"
159                 android:layout_height="70dp"
160                 android:layout_below="@id/three"
161                 android:layout_toRightOf="@id/clear"
162                 android:text="@string/result"
163                 android:textSize="40sp" />
164 
165             <Button
166                 android:id="@+id/divide"
167                 android:layout_width="80dp"
168                 android:layout_height="70dp"
169                 android:layout_alignParentRight="true"
170                 android:layout_below="@id/multiply"
171                 android:layout_toRightOf="@id/result"
172                 android:text="@string/divide"
173                 android:textSize="40sp" />
174 
175             <Button
176                 android:id="@+id/dot"
177                 android:layout_width="80dp"
178                 android:layout_height="70dp"
179                 android:layout_alignParentLeft="true"
180                 android:layout_below="@id/zero"
181                 android:text="@string/dot"
182                 android:textSize="40sp" />
183             <Button
184                 android:id="@+id/writeButton"
185                 android:layout_width="wrap_content"
186                 android:layout_height="wrap_content"
187                 android:layout_alignParentLeft="true"
188                 android:layout_below="@id/dot"
189                 android:text="@string/write"
190                 android:textSize="40sp" />
191             <Button
192                 android:id="@+id/readButton"
193                 android:layout_width="wrap_content"
194                 android:layout_height="wrap_content"
195                 android:layout_alignParentRight="true"
196                 android:layout_below="@id/dot"
197                 android:text="@string/read"
198                 android:textSize="40sp" />
199 
200             <CheckBox
201                 android:id="@+id/appendBox"
202                 android:text="@string/appendBox"
203                 android:layout_width="wrap_content"
204                 android:layout_height="wrap_content"
205                 android:layout_alignParentBottom="true"
206                 android:layout_toLeftOf="@+id/divide"
207                 android:layout_toStartOf="@+id/divide"
208                 android:layout_marginBottom="12dp"
209                 />
210 
211         </RelativeLayout>
212 
213         <EditText
214 
215             android:layout_width="match_parent"
216             android:layout_height="wrap_content"
217             android:id="@+id/textView" />
218 
219         <EditText
220 
221             android:layout_width="match_parent"
222             android:layout_height="wrap_content"
223             android:id="@+id/displayView" />
224 
225         <EditText
226             android:id="@+id/errorzero"
227             android:layout_width="fill_parent"
228             android:layout_height="wrap_content"
229             android:layout_gravity="center"
230             android:editable="false"
231             android:gravity="center"
232             />
233         <EditText
234             android:id="@+id/resultText"
235             android:layout_width="fill_parent"
236             android:layout_height="wrap_content"
237             android:layout_gravity="center"
238             android:editable="false"
239             android:gravity="left"
240             android:text="@string/resultText"
241             />
242     </LinearLayout>
243 </ScrollView>