一、说明
- 我使用的是Android Studio2021.12.1版本的;
- 本程序分为代码和素材以及运行结果三部分;
- 在将代码完全粘贴到软件中,常见问题就是图片丢失,这样需要将涉及到的图片导入到本项目下的drawable目录下。其他问题可在评论留言或自行解决;
- 我本人是高职学生,这个程序是自己做得,有些地方不够完善,同时不算太美观,因能力有限,请谅解;
二、代码段
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="42dp" android:orientation="horizontal"> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="11" android:text="≡" android:gravity="center" android:textSize="25sp" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="11" android:text="标准" android:gravity="center" android:textSize="25sp" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="11" android:text="→" android:gravity="center" android:textSize="25sp"/> <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="11" android:text="?" android:gravity="center" android:textSize="25sp"/> </LinearLayout> <TextView android:id="@+id/textView4" android:layout_width="match_parent" android:layout_height="101dp" android:gravity="right" android:text="0" android:textSize="80sp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/button11" android:layout_width="wrap_content" android:layout_height="70dp" android:layout_weight="1" android:backgroundTint="#FFFFFF" android:text="MC" android:textSize="15sp" /> <Button android:id="@+id/button12" android:layout_width="wrap_content" android:layout_height="70dp" android:layout_weight="1" android:backgroundTint="#FFFFFF" android:text="MR" android:textSize="15sp"/> <Button android:id="@+id/button13" android:layout_width="wrap_content" android:layout_height="70dp" android:layout_weight="1" android:backgroundTint="#FFFFFF" android:text="M+" android:textSize="15sp"/> <Button android:id="@+id/button14" android:layout_width="wrap_content" android:layout_height="70dp" android:layout_weight="1" android:backgroundTint="#FFFFFF" android:text="M-" android:textSize="15sp"/> <Button android:id="@+id/button15" android:layout_width="wrap_content" android:layout_height="70dp" android:layout_weight="1" android:backgroundTint="#FFFFFF" android:text="MS" android:textSize="15sp"/> <Button android:id="@+id/button16" android:layout_width="wrap_content" android:layout_height="70dp" android:layout_weight="1" android:backgroundTint="#FFFFFF" android:text="M``" android:textSize="15sp"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="84dp" android:orientation="horizontal"> <Button android:id="@+id/button17" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="#F6F3F3" android:text="%" android:textSize="30sp" /> <Button android:id="@+id/button18" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="#F6F3F3" android:text="ce" android:textSize="30sp" /> <Button android:id="@+id/button19" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="#F6F3F3" android:text="c" android:textSize="30sp" /> <Button android:id="@+id/button20" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="#F6F3F3" android:text="÷" android:textSize="30sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="78dp" android:orientation="horizontal"> <Button android:id="@+id/button17" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="#F6F3F3" android:text="1/x" android:textSize="22sp" /> <Button android:id="@+id/button18" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="#F6F3F3" android:text="x2" android:textSize="22sp" /> <Button android:id="@+id/button19" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="#F6F3F3" android:text="2√x" android:textSize="22sp" /> <Button android:id="@+id/button20" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="#FFEB3B" android:text="←" android:textSize="25sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="82dp" android:orientation="horizontal"> <Button android:id="@+id/button17" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="@color/white" android:text="7" android:textSize="30sp" /> <Button android:id="@+id/button18" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="@color/white" android:text="8" android:textSize="30sp" /> <Button android:id="@+id/button19" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="@color/white" android:text="9" android:textSize="30sp" /> <Button android:id="@+id/button20" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="#F6F3F3" android:text="×" android:textSize="30sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="82dp" android:orientation="horizontal"> <Button android:id="@+id/button17" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="@color/white" android:text="4" android:textSize="30sp" /> <Button android:id="@+id/button18" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="@color/white" android:text="5" android:textSize="30sp" /> <Button android:id="@+id/button19" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="@color/white" android:text="6" android:textSize="30sp" /> <Button android:id="@+id/button20" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="#F6F3F3" android:text="—" android:textSize="30sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="78dp" android:orientation="horizontal"> <Button android:id="@+id/button17" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="@color/white" android:text="1" android:textSize="30sp" /> <Button android:id="@+id/button18" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="@color/white" android:text="2" android:textSize="30sp" /> <Button android:id="@+id/button19" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="@color/white" android:text="3" android:textSize="30sp" /> <Button android:id="@+id/button20" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="#F6F3F3" android:text="+" android:textSize="30sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <Button android:id="@+id/button17" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="@color/white" android:text="+/-" android:textSize="30sp" /> <Button android:id="@+id/button18" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="@color/white" android:text="0" android:textSize="30sp" /> <Button android:id="@+id/button19" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="@color/white" android:text="." android:textSize="30sp" /> <Button android:id="@+id/button20" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_weight="1" android:backgroundTint="#03A9F4" android:text="=" android:textSize="30sp" /> </LinearLayout> </LinearLayout> </LinearLayout>
三、运行结果
四、部分图片资源