Android 计算器

article/2025/11/2 9:37:49

Android 计算器

开发环境:android stdio 3.6.1

最终效果:

竖屏:
在这里插入图片描述
横屏:
在这里插入图片描述
完整项目:百度网盘链接
密码 v89n

主要代码:

MainActivity.java:

package com.example.experience_two;import androidx.appcompat.app.AppCompatActivity;import android.content.Context;
import android.content.pm.PermissionGroupInfo;
import android.icu.util.VersionInfo;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.GridLayout;
import android.widget.TextView;import java.math.BigDecimal;
import java.net.CacheRequest;
import java.sql.BatchUpdateException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class MainActivity extends AppCompatActivity implements View.OnClickListener {private static final String TAG = "MainActivity";private GridLayout mGridLauout;private TextView text,answer;private int colCount,rowCount;private int screenWidthDp,screenHeightDp,ScreenWidthPx,ScreenHeightPx,flag=0;float density;int fontMaxCount1=11;float fontSize1=60;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);getSupportActionBar().hide();//去掉标题栏mGridLauout = (GridLayout) findViewById(R.id.GridLayout1);colCount = mGridLauout.getColumnCount();//按钮列数rowCount = mGridLauout.getRowCount();//按钮行数text=(TextView)findViewById(R.id.input_number);answer=(TextView)findViewById(R.id.out_number);text.setHorizontallyScrolling(true);//使text可以滑动WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);DisplayMetrics dm = new DisplayMetrics();wm.getDefaultDisplay().getMetrics(dm);ScreenWidthPx = dm.widthPixels;// 屏幕宽度(像素)ScreenHeightPx= dm.heightPixels; // 屏幕高度(像素)density = dm.density;//屏幕密度(0.75 / 1.0 / 1.5)int densityDpi = dm.densityDpi;//屏幕密度dpi(120 / 160 / 240)//屏幕宽度算法:屏幕宽度(像素)/屏幕密度screenWidthDp = (int) (ScreenWidthPx/density);//屏幕宽度(dp)screenHeightDp = (int)(ScreenHeightPx/density);//屏幕高度(dp)//设置按钮在下半屏幕内均匀分布for (int i = 0; i < mGridLauout.getChildCount(); i++) {Button button = (Button) mGridLauout.getChildAt(i);Log.e(TAG, "column:" + colCount + ";  screenwidth:" + ScreenWidthPx);button.setWidth(ScreenWidthPx / colCount);if(screenWidthDp<screenHeightDp){flag=1;button.setHeight(ScreenHeightPx/ 2 / rowCount);}//竖屏时按钮部分占屏幕的二分是一else{button.setHeight(ScreenHeightPx/rowCount*2/3);}//横屏时按钮部分占屏幕的三分之二button.setOnClickListener(this);}//为网格布局中的每个按钮注册监听器并动态设置大小if(savedInstanceState!=null){String s=savedInstanceState.getString("KEY");String s1=savedInstanceState.getString("ANSWER");text.setText(s);answer.setText(s1);}//恢复text和answer的数据}@Overrideprotected void onSaveInstanceState(Bundle outState) {super.onSaveInstanceState(outState);outState.putString("KEY",text.getText().toString());outState.putString("ANSWER",answer.getText().toString());}//在旋转屏幕时保存text和answer中的数据@Overridepublic void onClick(View view) {answer=(TextView)findViewById(R.id.out_number);String input=text.getText().toString();Button button=(Button)findViewById(view.getId());String btn=button.getText().toString();if(btn.charAt(0)>='0'&&btn.charAt(0)<='9'){if(input.equals("0")||input.matches("^.*[+−×÷]+0$")==true){text.setText(input.substring(0,input.length()-1)+btn);}//如果遇到以0打头的数字则先去掉0else if(!input.matches("^.*[%)]$")){text.setText(input+btn);}//如果text中为合法的式子则在末尾追加数字answer.setText(Calculator.Calculate(text.getText().toString()));//每次输入数字之后更新一次计算结果}//数字按钮else if(btn.matches("[+−×÷]+")&&!input.equals("")){if(input.matches("^.*[+−×÷.]+$")){text.setText(input.substring(0,text.length()-1)+btn);}//如果以运算符结尾,则改变运算符else{text.setText(input+btn);}//如果不以运算符结尾则追加运算符}//普通运算符else if(btn.equals("C")){text.setText("");answer.setText("");fontMaxCount1=11;fontSize1=60;//字符大小初始化if(flag==1)text.setTextSize(TypedValue.COMPLEX_UNIT_SP,fontSize1);}//清0按钮else if(!input.equals("")&&btn.equals("CE")){String str=input.substring(0,input.length()-1);if(str.equals("")){answer.setText("");}else if(str.charAt(str.length()-1)>='0'&&str.charAt(str.length()-1)<='9'){answer.setText(Calculator.Calculate(str));}//每回退一次计算结果更新一次text.setText(str);if(flag==1&&fontMaxCount1>11){fontMaxCount1-=1;} else if(flag==1){fontMaxCount1=11;fontSize1=60;text.setTextSize(TypedValue.COMPLEX_UNIT_SP,fontSize1);}//根据字符串长度动态调整字体大小}//退格按钮else if(btn.equals("%")){if(input.matches("^.*[0-9%]+$")){text.setText(input+btn);answer.setText(Calculator.Calculate(text.getText().toString()));}//只有数字或百分号之后才可以接百分号}//百分号else if(btn.equals(".")){if(!input.matches("^.*[0-9][.]+[0-9]+$|^.*[+−×÷.%)]$")){text.setText(input+btn);}//如果当前text最后一个数字含有小数点或以预算符结尾则加上小数点}//小数点else if(!input.equals("")&&btn.equals("+/−")){if(input.matches("^.*\\(−[0-9.]+\\)$")){String s1=input.substring(0,input.lastIndexOf("(−"))+input.substring(input.lastIndexOf("(−")+2,input.length()-1);text.setText(s1);answer.setText(Calculator.Calculate(s1));}//复数变正数else if(input.charAt(input.length()-1)>='0'&&input.charAt(input.length()-1)<='9'){int i;for (i = input.length()-1; i >= 0; i--) {if (!(input.charAt(i) == '.' || input.charAt(i) >= '0' && input.charAt(i) <= '9')) {break;}}int len=input.length();String s1=input.substring(0, i +1),s2=input.substring(i + 1,len );text.setText(s1+ "(−" + s2+ ")");answer.setText(Calculator.Calculate(text.getText().toString()));}//正数变复数}//正负号转换else if(btn.equals("=")){fontMaxCount1=10;fontSize1=60;if(flag==1)text.setTextSize(TypedValue.COMPLEX_UNIT_SP,fontSize1);if(!answer.getText().toString().equals("")){text.setText(answer.getText());}//answer的结果转到text显示answer.setText("");//answer清空}//等号else if(btn.equals("x²")){if(!btn.matches("^.*[+−×÷]$")){text.setText(input+"^2");answer.setText(Calculator.Calculate(input+"^2"));}}//平方else if(btn.equals("x³")){if(!btn.matches("^.*[+−×÷]$")){text.setText(input+"^3");answer.setText(Calculator.Calculate(input+"^3"));}}else if(btn.equals("yˣ")){if(!btn.matches("^.*[+−×÷]$")){text.setText(input+"^");}}else if(btn.equals("10ˣ")){if(!btn.matches("^.*[+−×÷]$")){System.out.println(input+"10^");text.setText(input+"10^");}else{System.out.println(input+"×10^");text.setText(input+"×10^");}}else if(btn.equals("√")){text.setText(input+"√");}//开平方else if(btn.equals("ˣ√y")){text.setText(input+btn);}else if(btn.equals("ln")||btn.equals("lg")){text.setText(input+btn+"(");}else if(btn.equals("Rad")){button.setText("Deg");}else if(btn.equals("Deg")){button.setText("Rad");}else if(btn.equals("x!")){if(!btn.matches("^.*[+−×÷]$")){text.setText(input+"!");answer.setText(Calculator.Calculate(input+"!"));}}//阶乘else if(btn.equals("EE")){text.setText(input+"E");}else if(btn.equals("eˣ")){text.setText(input+"e^");}else if(btn.equals("1/x")){text.setText(input+"^-1");}else if(btn.equals("(")){text.setText(input+btn);}else if(btn.equals(")")){input=input+btn;text.setText(input);answer.setText(Calculator.Calculate(input));//输入右括号之后也要更新answer}else if(btn.equals("sin")||btn.equals("cos")||btn.equals("tan")||btn.equals("sinh")||btn.equals("cosh")||btn.equals("tanh")){text.setText(input+btn+"(");}//三角函数运算else if(btn.equals("Rand")){input=input+btn;text.setText(input);answer.setText(Calculator.Calculate(input));}//随机数else if(btn.equals("π")){text.setText(input+Math.PI);}if(flag==1&&input.length()>fontMaxCount1){fontMaxCount1=fontMaxCount1+1;fontSize1=40;text.setTextSize(TypedValue.COMPLEX_UNIT_SP,fontSize1);//根据字符串长度动态调整字符大小}}//根据按钮的内容设置不同的响应函数
}

Calculator:

package com.example.experience_two;
import android.support.v4.app.INotificationSideChannel;import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Calculator {public static String Calculate(String input){while(input.matches("^.*\\(−?[0-9.]\\).*$")) {String reg = "\\((−?[0-9.])\\)";Pattern p = Pattern.compile(reg);Matcher m = p.matcher(input);while(m.find()) {input=input.replace(m.group(0),m.group(1));}}if(input.matches("^.*\\(.*\\).*$")){String reg = "\\(([^()]*)\\)";//匹配最里边的括号Pattern p = Pattern.compile(reg);Matcher m = p.matcher(input);while(m.find()) {input=input.replace(m.group(0),Calculate(m.group(1)));}}while(input.contains("!")){String reg = "([0-9]+)!";Pattern p=Pattern.compile(reg);Matcher m=p.matcher(input);while(m.find()) {String str=m.group(0),str1=m.group(1);int a=Integer.parseInt(str1);double b=1;for(int i=1;i<=a;i++){b=b*i;}input = input.replace(str, b + "");}}while(input.contains("sinh")) {System.out.println("sinh");String reg = "sinh\\(?(−?[0-9.]+)";Pattern p=Pattern.compile(reg);Matcher m=p.matcher(input);while(m.find()) {String str=m.group(0),str1=m.group(1);double a;if(str1.contains("−")){a=-Double.parseDouble(str1.substring(1));} else {a=Double.parseDouble(str1);}if(input.contains("+"+str)||input.contains("−"+str)||input.contains("×"+str)||input.contains("÷"+str)){input = input.replace(str, Math.sinh(a) + "");}else {input = input.replace(str,"×" + Math.sinh(a));}}if(input.startsWith("×")){input=input.substring(1);}input=input.replaceAll("-","−");}while(input.contains("cosh")) {String reg = "cosh\\(?(−?[0-9.]+)";Pattern p=Pattern.compile(reg);Matcher m=p.matcher(input);while(m.find()) {String str=m.group(0),str1=m.group(1);double a;if(str1.contains("−")){a=-Double.parseDouble(str1.substring(1,str1.length()));} else {a=Double.parseDouble(str1);}if(input.contains("+"+str)||input.contains("−"+str)||input.contains("×"+str)||input.contains("÷"+str)){input = input.replace(str, Math.cosh(a) + "");}else {input = input.replace(str,"×" + Math.cosh(a));}}if(input.startsWith("×")){input=input.substring(1);}input=input.replaceAll("-","−");}while(input.contains("tanh")) {System.out.println(input);String reg = "tanh\\(?(−?[0-9.]+)";Pattern p=Pattern.compile(reg);Matcher m=p.matcher(input);while(m.find()) {String str=m.group(0),str1=m.group(1);double a;if(str1.contains("−")){a=-Double.parseDouble(str1.substring(1));} else {a=Double.parseDouble(str1);}if(input.contains("+"+str)||input.contains("−"+str)||input.contains("×"+str)||input.contains("÷"+str)){input = input.replace(str, Math.tanh(a) + "");}else {input = input.replace(str,"×" + Math.tanh(a));}}if(input.startsWith("×")){input=input.substring(1);}input=input.replaceAll("-","−");}while(input.contains("sin")) {String reg = "sin\\(?(−?[0-9.]+)";Pattern p=Pattern.compile(reg);Matcher m=p.matcher(input);while(m.find()) {String str=m.group(0),str1=m.group(1);double a;if(str1.contains("−")){a=-Double.parseDouble(str1.substring(1));} else {a=Double.parseDouble(str1);}if(input.contains("+"+str)||input.contains("−"+str)||input.contains("×"+str)||input.contains("÷"+str)){input = input.replace(str, Math.sin(a) + "");}else {input = input.replace(str,"×" + Math.sin(a));}}if(input.startsWith("×")){input=input.substring(1);}input=input.replaceAll("-","−");}while(input.contains("cos")) {String reg = "cos\\(?(−?[0-9.]+)";Pattern p=Pattern.compile(reg);Matcher m=p.matcher(input);while(m.find()) {String str=m.group(0),str1=m.group(1);double a;if(str1.contains("−")){a=-Double.parseDouble(str1.substring(1));} else {a=Double.parseDouble(str1);}if(input.contains("+"+str)||input.contains("−"+str)||input.contains("×"+str)||input.contains("÷"+str)){input = input.replace(str, Math.cos(a) + "");}else {input = input.replace(str,"×" + Math.cos(a));}}if(input.startsWith("×")){input=input.substring(1);}input=input.replaceAll("-","−");}while(input.contains("tan")) {System.out.println("tan");String reg = "tan\\(?(−?[0-9.]+)";Pattern p=Pattern.compile(reg);Matcher m=p.matcher(input);while(m.find()) {String str=m.group(0),str1=m.group(1);double a;if(str1.contains("−")){a=-Double.parseDouble(str1.substring(1));} else {a=Double.parseDouble(str1);}if(input.contains("+"+str)||input.contains("−"+str)||input.contains("×"+str)||input.contains("÷"+str)){input = input.replace(str, Math.tan(a) + "");}else {input = input.replace(str,"×" + Math.tan(a));}}if(input.startsWith("×")){input=input.substring(1);}input=input.replaceAll("-","−");}while(input.contains("ln")) {String reg = "ln\\(?(−?[0-9.]+)";Pattern p=Pattern.compile(reg);Matcher m=p.matcher(input);while(m.find()) {String str=m.group(0),str1=m.group(1);double a;if(str1.contains("−")){a=-Double.parseDouble(str1.substring(1));} else {a=Double.parseDouble(str1);}if(input.contains("+"+str)||input.contains("−"+str)||input.contains("×"+str)||input.contains("÷"+str)){input = input.replace(str, Math.log(a) + "");}else {input = input.replace(str,"×" + Math.log(a));}}if(input.startsWith("×")){input=input.substring(1);}input=input.replaceAll("-","−");}while(input.contains("lg")) {String reg = "lg\\(?(−?[0-9.]+)";Pattern p=Pattern.compile(reg);Matcher m=p.matcher(input);while(m.find()) {String str=m.group(0),str1=m.group(1);double a;if(str1.contains("−")){a=-Double.parseDouble(str1.substring(1));} else {a=Double.parseDouble(str1);}if(input.contains("+"+str)||input.contains("−"+str)||input.contains("×"+str)||input.contains("÷"+str)){input = input.replace(str, Math.log10(a) + "");}else {input = input.replace(str,"×" + Math.log10(a));}}if(input.startsWith("×")){input=input.substring(1);}input=input.replaceAll("-","−");}while(input.contains("e")) {String reg = "e\\^(−?[0-9.]+)";Pattern p=Pattern.compile(reg);Matcher m=p.matcher(input);while(m.find()) {String str=m.group(0),str1=m.group(1);System.out.println(str1);double a;if(str1.contains("−")){a=-Double.parseDouble(str1.substring(1));} else {a=Double.parseDouble(str1);}                   b=Double.parseDouble(str2);}input=input.replace(m.group(1),Math.pow(a,b)+"");}input=input.replaceAll("-","−");}while(input.contains("√")) {String reg = "√\\(?([0-9.]+)";Pattern p=Pattern.compile(reg);Matcher m=p.matcher(input);while(m.find()) {String str=m.group(0),str1=m.group(1);double a;a=Double.parseDouble(str1);if(input.contains("+"+str)||input.contains("−"+str)||input.contains("×"+str)||input.contains("÷"+str)){input = input.replace(str, Math.sqrt(a) + "");}else {input = input.replace(str,"×" + Math.sqrt(a));}}if(input.startsWith("×")){input=input.substring(1);}input=input.replaceAll("-","−");}while(input.contains("%")){String reg = "((\\d*\\.*\\d+)%)";Pattern p=Pattern.compile(reg);Matcher m = p.matcher(input);while(m.find()){double a=0.01*Double.parseDouble(m.group(2));input=input.replace(m.group(1),a+"");}}while(input.contains("×")||input.contains("÷")) {String reg = "((−?\\d*\\.*\\d+)[×÷](−?\\d*\\.*\\d+))";Pattern p = Pattern.compile(reg);Matcher m = p.matcher(input);while (m.find()){double a,b;String str=m.group(0),str1=m.group(2).toString(),str2=m.group(3).toString();if(str1.contains("−")){a=-Double.parseDouble(str1.substring(1,str1.length()));} else {a=Double.parseDouble(str1);}if(str2.contains("−")){b=-Double.parseDouble(str2.substring(1,str2.length()));} else {b=Double.parseDouble(str2);}if (str.contains("×")){input=input.replace(str,a*b+"");} else {if(Math.abs(b)<1e-5) {return "error";}input=input.replace(str,a/b+"");}}}if(input.contains("E")){input="error";}input=input.replace("-","−");while(input.contains("+")||input.contains("−")){if(input.matches("^−\\d*\\.*\\d+$")) {break;};String reg = "((−?\\d*\\.*\\d+)[+−](−?\\d*\\.*\\d+))";Pattern p = Pattern.compile(reg);Matcher m = p.matcher(input);while (m.find()){double a,b;String str=m.group(0),str1=m.group(2).toString(),str2=m.group(3).toString();if(str1.contains("−")){a=-Double.parseDouble(str1.substring(1,str1.length()));} else {a=Double.parseDouble(str1);}if(str2.contains("−")){b=-Double.parseDouble(str2.substring(1,str2.length()));} else {b=Double.parseDouble(str2);}if (str.contains("+")){input=input.replace(str,a+b+"");} else {input=input.replace(str,a-b+"");}}input=input.replaceAll("-","−");}if(!input.matches("−?\\d*\\.*\\d+")){input="error!";}if(input.matches("^.*\\.0$")){int len=input.length();input=input.substring(0,len-2);}return input;}
}

竖屏布局xml文件:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:ignore="NewApi"android:theme="@android:style/Theme.Black.NoTitleBar"tools:context=".MainActivity"><TextViewandroid:id="@+id/input_number"android:layout_width="match_parent"android:layout_height="70dp"android:clickable="true"android:gravity="right"android:textColor="@color/button_one"android:textSize="60sp"app:layout_constraintBottom_toTopOf="@+id/out_number"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" /><TextViewandroid:id="@+id/out_number"android:layout_width="match_parent"android:layout_height="50dp"android:clickable="true"android:gravity="right"android:textColor="#c0c0c0"android:textSize="40sp"app:layout_constraintBottom_toTopOf="@+id/GridLayout1"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent"app:layout_constraintVertical_bias="0.662" /><GridLayoutandroid:id="@+id/GridLayout1"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:columnCount="4"android:rowCount="5"app:layout_constraintBottom_toBottomOf="parent"><Buttonandroid:id="@+id/number1"style="@style/btn_nomal_style"android:layout_row="3"android:layout_column="0"android:text="1" /><Buttonandroid:id="@+id/number2"style="@style/btn_nomal_style"android:layout_row="3"android:layout_column="1"android:text="2" /><Buttonandroid:id="@+id/number3"style="@style/btn_nomal_style"android:layout_row="3"android:layout_column="2"android:text="3" /><Buttonandroid:id="@+id/number4"style="@style/btn_nomal_style"android:layout_row="2"android:layout_column="0"android:text="4" /><Buttonandroid:id="@+id/number5"style="@style/btn_nomal_style"android:layout_row="2"android:layout_column="1"android:text="5" /><Buttonandroid:id="@+id/number6"style="@style/btn_nomal_style"android:layout_row="2"android:layout_column="2"android:text="6" /><Buttonandroid:id="@+id/number7"style="@style/btn_nomal_style"android:layout_row="1"android:layout_column="0"android:text="7" /><Buttonandroid:id="@+id/number8"style="@style/btn_nomal_style"android:layout_row="1"android:layout_column="1"android:text="8" /><Buttonandroid:id="@+id/number9"style="@style/btn_nomal_style"android:layout_row="1"android:layout_column="2"android:text="9"/><Buttonandroid:id="@+id/number0"style="@style/btn_nomal_style"android:layout_row="4"android:layout_column="1"android:text="0" /><Buttonandroid:id="@+id/clear"style="@style/btn_nomal_style"android:layout_row="0"android:layout_column="0"android:text="C"android:textColor="@color/button_one" /><Buttonandroid:id="@+id/back"style="@style/btn_nomal_style"android:layout_row="0"android:layout_column="1"android:text="CE"android:textColor="@color/button_one" /><Buttonandroid:id="@+id/add"style="@style/btn_nomal_style"android:layout_row="3"android:layout_column="3"android:text="+"android:textColor="@color/button_one" /><Buttonandroid:id="@+id/min"style="@style/btn_nomal_style"android:layout_row="2"android:layout_column="3"android:text="−"android:textColor="@color/button_one" /><Buttonandroid:id="@+id/mul"style="@style/btn_nomal_style"android:layout_row="1"android:layout_column="3"android:text="×"android:textColor="@color/button_one" /><Buttonandroid:id="@+id/div"style="@style/btn_nomal_style"android:layout_row="0"android:layout_column="3"android:text="÷"android:textColor="@color/button_one" /><Buttonandroid:id="@+id/dot"style="@style/btn_nomal_style"android:layout_row="4"android:layout_column="2"android:text="." /><Buttonandroid:id="@+id/equal"style="@style/btn_nomal_style"android:layout_row="4"android:layout_column="3"android:text="="android:textColor="@color/button_one" /><Buttonandroid:id="@+id/symbol"style="@style/btn_nomal_style"android:layout_row="0"android:layout_column="2"android:text="+/−"android:textColor="@color/button_one" /><Buttonandroid:id="@+id/percent"style="@style/btn_nomal_style"android:layout_row="4"android:layout_column="0"android:text="%" /></GridLayout></androidx.constraintlayout.widget.ConstraintLayout>

横屏布局xml文件:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:ignore="NewApi"android:theme="@android:style/Theme.Black.NoTitleBar"tools:context=".MainActivity"><TextViewandroid:id="@+id/input_number"android:layout_width="match_parent"android:layout_height="57sp"android:clickable="true"android:gravity="right"android:textColor="@color/button_one"android:textSize="45sp"app:layout_constraintBottom_toTopOf="@+id/out_number"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" /><TextViewandroid:id="@+id/out_number"android:layout_width="match_parent"android:layout_height="25sp"android:clickable="true"android:gravity="right"android:textColor="#c0c0c0"android:textSize="20sp"app:layout_constraintBottom_toTopOf="@+id/GridLayout1"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent"app:layout_constraintVertical_bias="0.90" /><GridLayoutandroid:id="@+id/GridLayout1"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:columnCount="8"android:rowCount="6"app:layout_constraintBottom_toBottomOf="parent"><Buttonandroid:id="@+id/mc"style="@style/btn_nomal_style_land"android:layout_row="0"android:layout_column="4"android:text="mc" /><Buttonandroid:id="@+id/madd"style="@style/btn_nomal_style_land"android:layout_row="0"android:layout_column="5"android:text="m+" /><Buttonandroid:id="@+id/mmin"style="@style/btn_nomal_style_land"android:layout_row="0"android:layout_column="6"android:text="m−" /><Buttonandroid:id="@+id/tenX"style="@style/btn_nomal_style_land"android:layout_row="0"android:layout_column="3"android:text="10ˣ" /><Buttonandroid:id="@+id/yX"style="@style/btn_nomal_style_land"android:layout_row="1"android:layout_column="3"android:text="yˣ" /><Buttonandroid:id="@+id/lg"style="@style/btn_nomal_style_land"android:layout_row="2"android:layout_column="3"android:text="lg" /><Buttonandroid:id="@+id/ln"style="@style/btn_nomal_style_land"android:layout_row="3"android:layout_column="3"android:text="ln" /><Buttonandroid:id="@+id/eX"style="@style/btn_nomal_style_land"android:layout_row="4"android:layout_column="3"android:text="eˣ" /><Buttonandroid:id="@+id/right_bracket"style="@style/btn_nomal_style_land"android:layout_row="0"android:layout_column="2"android:text=")" /><Buttonandroid:id="@+id/left_bracket"style="@style/btn_nomal_style_land"android:layout_row="0"android:layout_column="1"android:text="(" /><Buttonandroid:id="@+id/twoND"style="@style/btn_nomal_style_land"android:layout_row="0"android:layout_column="0"android:text="2nd" /><Buttonandroid:id="@+id/reciprocal"style="@style/btn_nomal_style_land"android:layout_row="1"android:layout_column="0"android:text="1/x" /><Buttonandroid:id="@+id/factorial"style="@style/btn_nomal_style_land"android:layout_row="2"android:layout_column="0"android:text="x!" /><Buttonandroid:id="@+id/sin"style="@style/btn_nomal_style_land"android:layout_row="3"android:layout_column="0"android:text="sin" /><Buttonandroid:id="@+id/sinh"style="@style/btn_nomal_style_land"android:layout_row="4"android:layout_column="0"android:text="sinh" /><Buttonandroid:id="@+id/rad"style="@style/btn_nomal_style_land"android:layout_row="5"android:layout_column="0"android:text="Rad" /><Buttonandroid:id="@+id/square"style="@style/btn_nomal_style_land"android:layout_row="1"android:layout_column="1"android:text="x²" /><Buttonandroid:id="@+id/sqrt"style="@style/btn_nomal_style_land"android:layout_row="2"android:layout_column="1"android:text="√" /><Buttonandroid:id="@+id/cos"style="@style/btn_nomal_style_land"android:layout_row="3"android:layout_column="1"android:text="cos" /><Buttonandroid:id="@+id/cosh"style="@style/btn_nomal_style_land"android:layout_row="4"android:layout_column="1"android:text="cosh" /><Buttonandroid:id="@+id/pai"style="@style/btn_nomal_style_land"android:layout_row="5"android:layout_column="1"android:text="π" /><Buttonandroid:id="@+id/cubic"style="@style/btn_nomal_style_land"android:layout_row="1"android:layout_column="2"android:text="x³" /><Buttonandroid:id="@+id/Xy"style="@style/btn_nomal_style_land"android:layout_row="2"android:layout_column="2"android:text="ˣ√y" /><Buttonandroid:id="@+id/tan"style="@style/btn_nomal_style_land"android:layout_row="3"android:layout_column="2"android:text="tan" /><Buttonandroid:id="@+id/tanh"style="@style/btn_nomal_style_land"android:layout_row="4"android:layout_column="2"android:text="tanh" /><Buttonandroid:id="@+id/EE"style="@style/btn_nomal_style_land"android:layout_row="5"android:layout_column="2"android:text="EE" /><Buttonandroid:id="@+id/rand"style="@style/btn_nomal_style_land"android:layout_row="5"android:layout_column="3"android:text="Rand" /><Buttonandroid:id="@+id/mmul"style="@style/btn_nomal_style_land"android:layout_row="0"android:layout_column="7"android:text="mr" /><Buttonandroid:id="@+id/number1"style="@style/btn_nomal_style_land"android:layout_row="4"android:layout_column="4"android:text="1" /><Buttonandroid:id="@+id/number2"style="@style/btn_nomal_style_land"android:layout_row="4"android:layout_column="5"android:text="2" /><Buttonandroid:id="@+id/number3"style="@style/btn_nomal_style_land"android:layout_row="4"android:layout_column="6"android:text="3" /><Buttonandroid:id="@+id/number4"style="@style/btn_nomal_style_land"android:layout_row="3"android:layout_column="4"android:text="4" /><Buttonandroid:id="@+id/number5"style="@style/btn_nomal_style_land"android:layout_row="3"android:layout_column="5"android:text="5" /><Buttonandroid:id="@+id/number6"style="@style/btn_nomal_style_land"android:layout_row="3"android:layout_column="6"android:text="6" /><Buttonandroid:id="@+id/number7"style="@style/btn_nomal_style_land"android:layout_row="2"android:layout_column="4"android:text="7" /><Buttonandroid:id="@+id/number8"style="@style/btn_nomal_style_land"android:layout_row="2"android:layout_column="5"android:text="8" /><Buttonandroid:id="@+id/number9"style="@style/btn_nomal_style_land"android:layout_row="2"android:layout_column="6"android:text="9"/><Buttonandroid:id="@+id/number0"style="@style/btn_nomal_style_land"android:layout_row="5"android:layout_column="5"android:text="0" /><Buttonandroid:id="@+id/clear"style="@style/btn_nomal_style_land"android:layout_row="1"android:layout_column="4"android:text="C"android:textColor="@color/button_one" /><Buttonandroid:id="@+id/back"style="@style/btn_nomal_style_land"android:layout_row="1"android:layout_column="5"android:text="CE"android:textColor="@color/button_one" /><Buttonandroid:id="@+id/add"style="@style/btn_nomal_style_land"android:layout_row="4"android:layout_column="7"android:text="+"android:textColor="@color/button_one" /><Buttonandroid:id="@+id/min"style="@style/btn_nomal_style_land"android:layout_row="3"android:layout_column="7"android:text="−"android:textColor="@color/button_one" /><Buttonandroid:id="@+id/mul"style="@style/btn_nomal_style_land"android:layout_row="2"android:layout_column="7"android:text="×"android:textColor="@color/button_one" /><Buttonandroid:id="@+id/div"style="@style/btn_nomal_style_land"android:layout_row="1"android:layout_column="7"android:text="÷"android:textColor="@color/button_one" /><Buttonandroid:id="@+id/dot"style="@style/btn_nomal_style_land"android:layout_row="5"android:layout_column="6"android:text="." /><Buttonandroid:id="@+id/equal"style="@style/btn_nomal_style_land"android:layout_row="5"android:layout_column="7"android:text="="android:textColor="@color/button_one" /><Buttonandroid:id="@+id/symbol"style="@style/btn_nomal_style_land"android:layout_row="1"android:layout_column="6"android:text="+/−"android:textColor="@color/button_one" /><Buttonandroid:id="@+id/percent"style="@style/btn_nomal_style_land"android:layout_row="5"android:layout_column="4"android:text="%" /></GridLayout></androidx.constraintlayout.widget.ConstraintLayout>

http://chatgpt.dhexx.cn/article/eZk4QO4c.shtml

相关文章

android计算器

1、效果预览 2、项目布局 3、main.xml文件内容 <LinearLayout xmlns:android"http://schemas.android.com/apk/res/android"xmlns:tools"http://schemas.android.com/tools"android:layout_width"fill_parent"android:layout_height"fi…

Android计算器简单实现及代码分析

一、UI布局及代码 页面效果 布局代码 <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas.android.com/apk/res/android"android:layout_width"match_parent"android:layout_height"…

Android计算器——入门

Android计算器—入门 作者&#xff1a;黑衣侠客 一.前言 这是我写的第一个App&#xff0c;利用的是《安卓第一行代码》第三章&#xff0c;UI控件的一些知识&#xff0c;然后整体结构综合了一些CSDN博客和简书上的一些著作&#xff0c;同样&#xff0c;在写Android计算器&…

基础复习——项目练习——计算器

布局&#xff1a; <LinearLayout xmlns:android"http://schemas.android.com/apk/res/android"android:layout_width"match_parent"android:layout_height"match_parent"android:background"#eeeeee"android:orientation"vert…

安卓-AndroidStudio-计算器

安卓--Android Studio--简易计算器 结果截图关键代码讲解完整代码 本人是一名在校学生&#xff0c;由于上个学期的课程内容包括移动开发&#xff0c;其中的实验也算是大部分是自己完成的&#xff0c;所以算是写博客记录一下吧。 第一次写&#xff0c;有啥问题及时交流哈&#x…

Django数据库操作

目录 一、Django/ORM框架介绍及配置 1.1、ORM框架介绍 1.2、Django数据库配置 二、定义模型类数 2.1、定义模型类 2.2、迁移 2.3、插入数据 三、单表据库操作(增、删、改、查) 3.1、增 3.2、删 3.3、改 3.4查&#xff08;重点&#xff09; 四、两表联查 4.1、一对…

Qt入门------数据库操作

文章目录 一、数据库1.数据库驱动2.查询驱动3.连接数据库4.执行sql语句5.插入数据6.事务 二 &#xff0c;sql模型类1.QSqlQueryModel模型2.QSqlTableModel模型3.QSqlRelationalTableModel模型 一、数据库 Qt中的Qt SQL模块提供了对数据库的支持&#xff0c;模块中类可分为三层…

Java的数据库操作

Java的数据库操作&#xff0c;上学期末的课设是用到的&#xff0c;然而老师把JDBC连接mysql数据库的代码和配置文件已经给好了&#xff0c;那时对它可以说是只有一点点印象。 今天跟着书走一边敲一边&#xff0c;总算是有所进步。 数据库表的创建和初始数据的操作&#xff0c…

一文详解python中的数据库操作

python中的数据库操作 一、数据库编程接口1. 连接对象 二、使用内置的SQLite1.创建数据库文件2.操作SQLite 三、MySql数据库的使用3.1 安装MySql3.2 设置环境变量3.3 启动MySql3.4 使用navicat for mysql 管理软件3.5 安装PyMysql模块3.6 连接数据库 四、创建数据表4.1 创建boo…

数据库操作练习题

如何查看员工表中的所有字段&#xff1f; 如何查看员工表中的姓名和性别&#xff1f; 如何知道每个员工一年的总收入&#xff1f; 怎么查看女员工的信息&#xff1f; 如何查看月薪范围位于 8000 到 12000 之间的员工&#xff1f; 查询员工中叫做“张三”、“李四” 或“张飞”的…

MySQL(一)数据库操作

1.关系型数据库与非关系型数据库区别与联系 1.关系型数据库 ( SQL ) MySQL , Oracle , SQL Server , SQLite , DB2 , … 关系型数据库通过外键关联来建立表与表之间的关系 2.非关系型数据库 ( NOSQL ) Redis , MongoDB , … 非关系型数据库通常指数据以对象的形式存储在数据…

使用ORACLE 进行数据库操作

上一期讲了 如何创建表&#xff0c;例如我们创建了一个 名为 t_customer 的表&#xff0c;格式为下&#xff1a; create table t_customer(cust_id int primary key,cust_name varchar(20),cust_gender char(3),cust_age int,cust_birthday date,cust_height number(3,2),cust…

C#数据库操作

功能需求 1&#xff0c;利用随机数模拟产生每次考试成绩 2&#xff0c;将每次考试成绩存入到数据库 3&#xff0c;将每次考试成绩划分优、良、中、差、不及格五类&#xff0c;并作为查询条件&#xff0c;查询符合每种水平的成绩 技术知识点 1.random类的使用 2.数据库的链…

云数据库操作

1 云数据库创建 每一个list就相当于一个表&#xff0c;每个记录就是一条内容 云数据库存储形式是JSON2 读取云数据库值 数据库初始化 const db wx.cloud.database() 连接数据库 db.collection(需要连接的数据列表名)可以通过.doc(‘具体id号’)获取具体的信息内容获取年、月…

Android数据库操作

Android内置了一个名为SQLite的关系型数据库&#xff0c;这是一款轻量型的数据库&#xff0c;操作十分简便。SQLite与别的数据库不同的是&#xff0c;它没有数据类型。可以保存任何类型的数据到你所想要保存的任何表的任何列中。但它又支持常见的类型比如: NULL, VARCHAR, TEXT…

数据库基本操作

一、数据库基本操作 1.数据库的基本操作 -- 1.数据库的基本操作 使用test数据库 USE test; -- 查看当前test数据库中所有表 MySQL命令 SHOW TABLES; -- 查表的基本信息 SHOW CREATE TABLE student; -- -- 查看表的字段信息 desc student; 2.数据表的基本操作 -- 2.数据表的…

数据库基础操作

一、数据库的操作 数据库与客户端是通过网络进行交互的。 1、显示当前数据库 sql语句必须以 ; 结尾 show databases; 2、创建数据库 create database 数据库名; ->如果数据库sql敲错了&#xff0c;会有提示。 ->如果sql敲错了&#xff0c;可以按 ctrlc来终止sql。…

数据库的基本操作

目录 一、数据库的基本操作 1、数据库的登录及退出 2、查看所有数据库 3、显示数据库版本 4、显示时间 5、创建数据库 6、查看创建数据库的语句 7、查看当前使用的数据库 8、查看当前用户 9、使用某个数据库 10、删除数据库 二、数据表的基本操作 1、查看当前数据…

如何在IDEA上创建一个JSP项目【亲测有效】

idea上创建一个jsp项目 1、创建一个Java项目 2、创建成功后右击项目名称&#xff0c;点击Add Framework support 3、选择web application 选择适合版本&#xff0c;创建 4、创建成功后项目中会出现web文件夹 5、点击属性&#xff0c;进行配置 6、在project中配置jdk(你自己电脑…

Eclipse中安装配置Tomcat和创建JSP项目

这里写自定义目录标题 安装配置Tomcat创建JSP项目 安装配置Tomcat 下载并解压Tomcat到指定目录Eclipse菜单栏中找到Window–>Preperences->Server->Runtime Environments->Add 3.选择Tomcat文件夹 4.在Eclipse中找到Servers视图窗口&#xff0c;创建Tomcat服务…