Android 计算器制作 1.布局
1.activity_main.xml文件布局
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | <LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http://schemas.android.com/tools" android:layout_width= "match_parent" android:layout_height= "match_parent" android:paddingLeft= "@dimen/activity_horizontal_margin" android:paddingRight= "@dimen/activity_horizontal_margin" android:paddingTop= "@dimen/activity_vertical_margin" android:orientation= "vertical" android:paddingBottom= "@dimen/activity_vertical_margin" tools:context= ".MainActivity" > <EditText android:layout_width= "fill_parent" android:layout_height= "90dp" android:gravity= "right|center_vertical" android:id= "@+id/edit_text1" android:background= "@drawable/white_bg" /> <LinearLayout android:layout_marginTop= "10dp" android:orientation= "vertical" android:layout_width= "fill_parent" android:layout_height= "fill_parent" > <LinearLayout android:layout_weight= "1" android:layout_width= "fill_parent" android:layout_height= "0dp" android:id= "@+id/ll1" android:orientation= "horizontal" > <Button android:layout_weight= "1" android:layout_width= "0dp" android:layout_height= "fill_parent" android:text= "C" android:textSize= "30sp" android:id= "@+id/bt_clear" /> <Button android:layout_weight= "1" android:layout_width= "0dp" android:layout_height= "fill_parent" android:text= "DEL" android:textSize= "30sp" android:id= "@+id/bt_del" /> <Button android:layout_weight= "1" android:layout_width= "0dp" android:layout_height= "fill_parent" android:text= "÷" android:textSize= "30sp" android:id= "@+id/bt_divide" /> <Button android:layout_weight= "1" android:layout_width= "0dp" android:layout_height= "fill_parent" android:text= "×" android:textSize= "30sp" android:id= "@+id/bt_multipy" /> </LinearLayout> <LinearLayout android:layout_weight= "1" android:layout_width= "fill_parent" android:layout_height= "0dp" android:id= "@+id/ll2" android:orientation= "horizontal" > <Button android:layout_weight= "1" android:layout_width= "0dp" android:layout_height= "fill_parent" android:text= "7" android:textSize= "30sp" android:id= "@+id/bt_7" /> <Button android:layout_weight= "1" android:layout_width= "0dp" android:layout_height= "fill_parent" android:text= "8" android:textSize= "30sp" android:id= "@+id/bt_8" /> <Button android:layout_weight= "1" android:layout_width= "0dp" android:layout_height= "fill_parent" android:text= "9" android:textSize= "30sp" android:id= "@+id/bt_9" /> <Button android:layout_weight= "1" android:layout_width= "0dp" android:layout_height= "fill_parent" android:text= "-" android:textSize= "30sp" android:id= "@+id/bt_minuse" /> </LinearLayout> <LinearLayout android:layout_weight= "1" android:layout_width= "fill_parent" android:layout_height= "0dp" android:id= "@+id/ll3" android:layout_below= "@id/ll2" android:orientation= "horizontal" > <Button android:layout_weight= "1" android:layout_width= "0dp" android:layout_height= "fill_parent" android:text= "4" android:textSize= "30sp" android:id= "@+id/bt_4" /> <Button android:layout_weight= "1" android:layout_width= "0dp" android:layout_height= "fill_parent" android:text= "5" android:textSize= "30sp" android:id= "@+id/bt_5" /> <Button android:layout_weight= "1" android:layout_width= "0dp" android:layout_height= "fill_parent" android:text= "6" android:textSize= "30sp" android:id= "@+id/bt_6" /> <Button android:layout_weight= "1" android:layout_width= "0dp" android:layout_height= "fill_parent" android:text= "+" android:textSize= "30sp" android:id= "@+id/bt_plus" /> </LinearLayout> <LinearLayout android:layout_weight= "2" android:layout_width= "fill_parent" android:layout_height= "0dp" > <LinearLayout android:orientation= "vertical" android:layout_weight= "3" android:layout_width= "0dp" android:layout_height= "fill_parent" > <LinearLayout android:layout_weight= "1" android:layout_width= "fill_parent" android:layout_height= "0dp" > <Button android:layout_weight= "1" android:id= "@+id/btn_1" android:text= "1" android:textSize= "30sp" android:layout_width= "0dp" android:layout_height= "fill_parent" /> <Button android:layout_weight= "1" android:id= "@+id/btn_2" android:text= "2" android:textSize= "30sp" android:layout_width= "0dp" android:layout_height= "fill_parent" /> <Button android:layout_weight= "1" android:id= "@+id/btn_3" android:text= "3" android:textSize= "30sp" android:layout_width= "0dp" android:layout_height= "fill_parent" /> </LinearLayout> <LinearLayout android:layout_weight= "1" android:layout_width= "fill_parent" android:layout_height= "0dp" > <Button android:layout_weight= "2" android:id= "@+id/btn_0" android:text= "0" android:textSize= "30sp" android:layout_width= "0dp" android:layout_height= "fill_parent" /> <Button android:layout_weight= "1" android:id= "@+id/btn_point" android:text= "." android:textSize= "30sp" android:layout_width= "0dp" android:layout_height= "fill_parent" /> </LinearLayout> </LinearLayout> <LinearLayout android:layout_weight= "1" android:layout_width= "0dp" android:layout_height= "fill_parent" > <Button android:layout_width= "fill_parent" android:layout_height= "fill_parent" android:text= "=" android:id= "@+id/btn_dengyu" android:textSize= "30sp" /> </LinearLayout> </LinearLayout> </LinearLayout> </LinearLayout> |
2.mainfest.xml设置
1 2 | <activity android:theme= "@android:style/Theme.Black.NoTitleBar" /> //主题 黑色 没有标题 |
3.color.xml的写法
1 2 3 4 5 | <?xml version= "1.0" encoding= "utf-8" ?> <resources> <color name= "white" >#ffffff</color> <color name= "black" ># 000000 </color> </resources> |
4.drawable 下创建 white_bg.xml作为EditText白色背景
1 2 3 4 5 6 7 8 | <?xml version= "1.0" encoding= "utf-8" ?> <shape xmlns:android= "http://schemas.android.com/apk/res/android" > <corners android:radius= "5dp" /> //角 半径5dp 圆角 <solid //填充色 android:color= "@color/white" /> </shape> |
①<corners/>:设置圆角。android:radius="5dp":圆角半径为5dp。
②<gradient/>:图像颜色的渐变。开始颜色:startColor="@color/white"。结束颜色:endColor="@color/red"
③<stroke/>:边框。width="1dp":边框宽度。color="@color/black":边框颜色。
④<solid/>:填充色。color="@color/white":填充色为白色。
分类:
Android 学习
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
· ThreeJs-16智慧城市项目(重磅以及未来发展ai)
· .NET 原生驾驭 AI 新基建实战系列(一):向量数据库的应用与畅想
· Ai满嘴顺口溜,想考研?浪费我几个小时
· Browser-use 详细介绍&使用文档
· 软件产品开发中常见的10个问题及处理方法