欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android?Studio實現(xiàn)簡單計算器開發(fā)

 更新時間:2022年05月20日 14:56:04   作者:echo_千  
這篇文章主要為大家詳細介紹了Android?Studio實現(xiàn)簡單計算器開發(fā),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android Studio實現(xiàn)簡單計算器開的具體代碼,供大家參考,具體內容如下

效果展示:

路徑和文件:

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
? ? package="com.example.calculator">
?
? ? <application
? ? ? ? android:allowBackup="true"
? ? ? ? android:icon="@mipmap/ic_launcher"
? ? ? ? android:label="@string/app_name"
? ? ? ? android:roundIcon="@mipmap/ic_launcher_round"
? ? ? ? android:supportsRtl="true"
? ? ? ? android:theme="@style/AppTheme">
? ? ? ? <activity android:name=".MainActivity">
? ? ? ? ? ? <intent-filter>
? ? ? ? ? ? ? ? <action android:name="android.intent.action.MAIN" />
?
? ? ? ? ? ? ? ? <category android:name="android.intent.category.LAUNCHER" />
? ? ? ? ? ? </intent-filter>
? ? ? ? </activity>
? ? </application>
?
</manifest>

MainActivity.java

package com.example.calculator;?
?
import android.os.Bundle;
?
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
?
import androidx.appcompat.app.AppCompatActivity;
?
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
?
public class MainActivity extends AppCompatActivity {
?
? ? private ?StringBuilder show_equation=new StringBuilder();//顯示運算式
? ? private ?ArrayList calculate_equation;//計算式
? ? private ?int signal=0;//為0 時表示剛輸入狀態(tài);為1 時表示當前在輸出結果上繼續(xù)輸入
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? //初始化
? ? ? ? show_equation=new StringBuilder();
? ? ? ? calculate_equation=new ArrayList<>();
? ? ? ? Button zero=(Button)findViewById(R.id.zero);
? ? ? ? Button one=(Button)findViewById(R.id.one);
? ? ? ? Button two=(Button)findViewById(R.id.two);
? ? ? ? Button three=(Button)findViewById(R.id.three);
? ? ? ? Button four=(Button)findViewById(R.id.four);
? ? ? ? Button five=(Button)findViewById(R.id.five);
? ? ? ? Button six=(Button)findViewById(R.id.six);
? ? ? ? Button seven=(Button)findViewById(R.id.seven);
? ? ? ? Button eight=(Button)findViewById(R.id.eight);
? ? ? ? Button nine=(Button)findViewById(R.id.nine);
? ? ? ? Button cls=(Button)findViewById(R.id.cls);
? ? ? ? Button div=(Button)findViewById(R.id.div);
? ? ? ? Button mul=(Button)findViewById(R.id.mul);
? ? ? ? Button backspace=(Button)findViewById(R.id.Backspace);
? ? ? ? Button sub=(Button)findViewById(R.id.sub);
? ? ? ? Button add=(Button)findViewById(R.id.add);
? ? ? ? final Button equal=(Button)findViewById(R.id.equal);
? ? ? ? final Button point=(Button)findViewById(R.id.spot);
? ? ? ? final EditText result=(EditText)findViewById(R.id.result);
? ? ? ? result.setCursorVisible(true);
? ? ? ? disableShowInput(result);
? ? ? ? //點擊文本框時光標始終在文本末尾
? ? ? ? result.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View view) {
? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? zero.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v){
? ? ? ? ? ? ? ? if(!(show_equation.toString().equals("0"))){
? ? ? ? ? ? ? ? ? ? if(signal==0){
? ? ? ? ? ? ? ? ? ? ? ? show_equation.append("0");
? ? ? ? ? ? ? ? ? ? ? ? //顯示運算式
? ? ? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? ? ? //將光標定位到文本末尾
? ? ? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? ? ? show_equation.delete(0,show_equation.length());
? ? ? ? ? ? ? ? ? ? ? ? show_equation.append("0");
? ? ? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? ? ? ? ? signal=0;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? //接下來1到9每個控件依次進行此設置
? ? ? ? //保證若是在結果上進行輸入時清除結果然后顯示點擊的數(shù)字
? ? ? ? //若是正常輸入則直接在運算式末尾加上點擊的數(shù)字并顯示
? ? ? ? one.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? if(signal==0){
? ? ? ? ? ? ? ? ? ? show_equation.append("1");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? show_equation.delete(0,show_equation.length());
? ? ? ? ? ? ? ? ? ? show_equation.append("1");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? ? ? signal=0;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? two.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? if(signal==0){
? ? ? ? ? ? ? ? ? ? show_equation.append("2");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? show_equation.delete(0,show_equation.length());
? ? ? ? ? ? ? ? ? ? show_equation.append("2");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? ? ? signal=0;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? three.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? if(signal==0){
? ? ? ? ? ? ? ? ? ? show_equation.append("3");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? show_equation.delete(0,show_equation.length());
? ? ? ? ? ? ? ? ? ? show_equation.append("3");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? ? ? signal=0;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? four.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? if(signal==0){
? ? ? ? ? ? ? ? ? ? show_equation.append("4");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? show_equation.delete(0,show_equation.length());
? ? ? ? ? ? ? ? ? ? show_equation.append("4");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? ? ? signal=0;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? five.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? if(signal==0){
? ? ? ? ? ? ? ? ? ? show_equation.append("5");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? show_equation.delete(0,show_equation.length());
? ? ? ? ? ? ? ? ? ? show_equation.append("5");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? ? ? signal=0;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? six.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? if(signal==0){
? ? ? ? ? ? ? ? ? ? show_equation.append("6");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? show_equation.delete(0,show_equation.length());
? ? ? ? ? ? ? ? ? ? show_equation.append("6");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? ? ? signal=0;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? seven.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? if(signal==0){
? ? ? ? ? ? ? ? ? ? show_equation.append("7");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? show_equation.delete(0,show_equation.length());
? ? ? ? ? ? ? ? ? ? show_equation.append("7");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? ? ? signal=0;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? eight.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? if(signal==0){
? ? ? ? ? ? ? ? ? ? show_equation.append("8");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? show_equation.delete(0,show_equation.length());
? ? ? ? ? ? ? ? ? ? show_equation.append("8");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? ? ? signal=0;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? nine.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? if(signal==0){
? ? ? ? ? ? ? ? ? ? show_equation.append("9");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? show_equation.delete(0,show_equation.length());
? ? ? ? ? ? ? ? ? ? show_equation.append("9");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? ? ? signal=0;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? //清屏
? ? ? ? cls.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? show_equation.delete(0,show_equation.length());
? ? ? ? ? ? ? ? calculate_equation.clear();
? ? ? ? ? ? ? ? signal=0;
? ? ? ? ? ? ? ? result.setText("");
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? //后退鍵
? ? ? ? //若在結果上使用,則直接清屏
? ? ? ? //正常輸入時使用,后退一格
? ? ? ? backspace.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? if(!(show_equation.toString().equals(""))) {
? ? ? ? ? ? ? ? ? ? if(signal==0){
? ? ? ? ? ? ? ? ? ? ? ? show_equation.deleteCharAt(show_equation.length() - 1);
? ? ? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? ? ? show_equation.delete(0,show_equation.length());
? ? ? ? ? ? ? ? ? ? ? ? result.setText("");
? ? ? ? ? ? ? ? ? ? ? ? signal=0;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? //小數(shù)點的點擊事件
? ? ? ? point.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? //正常輸入時點擊小數(shù)點的處理邏輯
? ? ? ? ? ? ? ? if(signal==0){
? ? ? ? ? ? ? ? ? ? //把運算式賦給字符串a(chǎn)
? ? ? ? ? ? ? ? ? ? String a=show_equation.toString();
? ? ? ? ? ? ? ? ? ? //運算式為空,直接加一個小數(shù)點并顯示
? ? ? ? ? ? ? ? ? ? if(a.equals("")){
? ? ? ? ? ? ? ? ? ? ? ? show_equation.append(".");
? ? ? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? //運算式不為空
? ? ? ? ? ? ? ? ? ? else{
? ? ? ? ? ? ? ? ? ? ? ? int i;
? ? ? ? ? ? ? ? ? ? ? ? char t='0';
? ? ? ? ? ? ? ? ? ? ? ? //從運算式末尾向前遍歷,碰到'.''+''-''*''/'后結束遍歷退出
? ? ? ? ? ? ? ? ? ? ? ? for(i=a.length();i>0;i--){
? ? ? ? ? ? ? ? ? ? ? ? ? ? t=a.charAt(i-1);
? ? ? ? ? ? ? ? ? ? ? ? ? ? if(t=='.'||t=='+'||t=='-'||t=='*'||t=='/')
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? //i==0表示遍歷運算式?jīng)]有發(fā)現(xiàn)'.''+''-''*''/',則直接在運算式末尾加小數(shù)點
? ? ? ? ? ? ? ? ? ? ? ? if(i==0){
? ? ? ? ? ? ? ? ? ? ? ? ? ? show_equation.append(".");
? ? ? ? ? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? //在碰到小數(shù)點前碰到了'+''-''*''/',也直接在運算式末尾加小數(shù)點
? ? ? ? ? ? ? ? ? ? ? ? else if(t=='+'||t=='-'||t=='*'||t=='/'){
? ? ? ? ? ? ? ? ? ? ? ? ? ? show_equation.append(".");
? ? ? ? ? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? //以上條件均不滿足,若說明遍歷碰到了小數(shù)點,因為一個數(shù)不能同時有兩個小數(shù)點,所以此次點擊小數(shù)點不做處理
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? //在結果上點擊小數(shù)點,直接清屏然后加上小數(shù)點并顯示
? ? ? ? ? ? ? ? else{
? ? ? ? ? ? ? ? ? ? show_equation.delete(0,show_equation.length());
? ? ? ? ? ? ? ? ? ? show_equation.append(".");
? ? ? ? ? ? ? ? ? ? result.setText(".");
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? ? ? signal=0;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
?
? ? ? ? equal.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? //判斷用戶是否輸入了內容
? ? ? ? ? ? ? ? if(!show_equation.toString().equals("")&&!(show_equation.toString().equals("錯誤"))){
? ? ? ? ? ? ? ? ? ? signal = 1;//表示在輸入結果上
? ? ? ? ? ? ? ? ? ? char temp = show_equation.charAt(show_equation.length() - 1);//把運算式的最后一個字符賦給temp
? ? ? ? ? ? ? ? ? ? if (show_equation.charAt(0) == '-')//如果運算式的第一個字符是'-',說明用戶是想輸入一個負數(shù)
? ? ? ? ? ? ? ? ? ? ? ? show_equation.insert(0, "0");//此時在運算式的最前面加一個0,用'0-運算數(shù)'表示負數(shù)
? ? ? ? ? ? ? ? ? ? if (temp == '+' || temp == '-')//若為加減
? ? ? ? ? ? ? ? ? ? ? ? show_equation.append("0");//則結尾默認加減零
? ? ? ? ? ? ? ? ? ? if (temp == '*' || temp == '/')//若為乘除
? ? ? ? ? ? ? ? ? ? ? ? show_equation.append("1");//則結尾默認乘除1
? ? ? ? ? ? ? ? ? ? StringBuilder temp1=new StringBuilder();
? ? ? ? ? ? ? ? ? ? //從頭遍歷運算式
? ? ? ? ? ? ? ? ? ? for(int i=0;i<show_equation.length();i++){
? ? ? ? ? ? ? ? ? ? ? ? if(show_equation.charAt(i)>='0'&&show_equation.charAt(i)<='9'||show_equation.charAt(i)=='.'){
? ? ? ? ? ? ? ? ? ? ? ? ? ? //如果是連著的數(shù)字和小數(shù)點,那就一個一個的拼到temp1中,作為一個完整的運算數(shù)
? ? ? ? ? ? ? ? ? ? ? ? ? ? temp1.append(String.valueOf(show_equation.charAt(i)));
? ? ? ? ? ? ? ? ? ? ? ? }else if(show_equation.charAt(i)=='N'){
? ? ? ? ? ? ? ? ? ? ? ? ? ? //如果是NaN就直接把'NaN'加進計算式里
? ? ? ? ? ? ? ? ? ? ? ? ? ? calculate_equation.add("NaN");
? ? ? ? ? ? ? ? ? ? ? ? ? ? //跳過2個字符
? ? ? ? ? ? ? ? ? ? ? ? ? ? i=i+2;
? ? ? ? ? ? ? ? ? ? ? ? }else if(show_equation.charAt(i)=='∞'){
? ? ? ? ? ? ? ? ? ? ? ? ? ? //如果是∞就直接把'∞'加進計算式里
? ? ? ? ? ? ? ? ? ? ? ? ? ? calculate_equation.add("∞");
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? else//這種就是遍歷到'+''-''*''/'這四種運算符的情況
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? //如果temp1長度不為0,說明運算符前有運算數(shù),則把該運算數(shù)添加進計算式中并清空temp1中的內容
? ? ? ? ? ? ? ? ? ? ? ? ? ? if(temp1.length()!=0){
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? calculate_equation.add(temp1.toString());
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? temp1.delete(0,temp1.length());
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? //把運算符添加進去
? ? ? ? ? ? ? ? ? ? ? ? ? ? calculate_equation.add(String.valueOf(show_equation.charAt(i)));
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? //把最后一個運算數(shù)加進運算式里
? ? ? ? ? ? ? ? ? ? if(temp1.length()!=0){
? ? ? ? ? ? ? ? ? ? ? ? calculate_equation.add(temp1.toString());
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? calculate_equation.add("#");
? ? ? ? ? ? ? ? ? ? //調用calculate計算出結果返回給temp8
? ? ? ? ? ? ? ? ? ? String temp8=calculate(calculate_equation);
? ? ? ? ? ? ? ? ? ? result.setText(temp8);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? ? ? //清空運算式和計算式
? ? ? ? ? ? ? ? ? ? show_equation.delete(0,show_equation.length());
? ? ? ? ? ? ? ? ? ? calculate_equation.clear();
? ? ? ? ? ? ? ? ? ? //將結果賦給運算式
? ? ? ? ? ? ? ? ? ? show_equation.append(temp8);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? add.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? //判斷用戶是否輸入了內容
? ? ? ? ? ? ? ? if(!(show_equation.toString().equals(""))&&!(show_equation.toString().equals("錯誤"))) {
? ? ? ? ? ? ? ? ? ? signal=0;
? ? ? ? ? ? ? ? ? ? char temp=show_equation.charAt(show_equation.length()-1);
? ? ? ? ? ? ? ? ? ? if(temp=='+'||temp=='-'||temp=='*'||temp=='/')
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? show_equation.deleteCharAt(show_equation.length()-1);
? ? ? ? ? ? ? ? ? ? ? ? show_equation.append("+");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? show_equation.append("+");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? sub.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? //判斷用戶是否輸入了內容
? ? ? ? ? ? ? ? if(!(show_equation.toString().equals(""))&&!(show_equation.toString().equals("錯誤"))) {
? ? ? ? ? ? ? ? ? ? signal=0;
? ? ? ? ? ? ? ? ? ? char temp=show_equation.charAt(show_equation.length()-1);
? ? ? ? ? ? ? ? ? ? if(temp=='+'||temp=='-'||temp=='*'||temp=='/')
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? show_equation.deleteCharAt(show_equation.length()-1);
? ? ? ? ? ? ? ? ? ? ? ? show_equation.append("-");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? show_equation.append("-");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else if(!(show_equation.toString().equals("錯誤"))){
? ? ? ? ? ? ? ? ? ? signal=0;
? ? ? ? ? ? ? ? ? ? show_equation.append("-");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
?
? ? ? ? mul.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? //判斷用戶是否輸入了內容
? ? ? ? ? ? ? ? if(!(show_equation.toString().equals(""))&&!(show_equation.toString().equals("錯誤"))) {
? ? ? ? ? ? ? ? ? ? signal=0;
? ? ? ? ? ? ? ? ? ? char temp=show_equation.charAt(show_equation.length()-1);
? ? ? ? ? ? ? ? ? ? if(temp=='+'||temp=='-'||temp=='*'||temp=='/')
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? show_equation.deleteCharAt(show_equation.length()-1);
? ? ? ? ? ? ? ? ? ? ? ? show_equation.append("*");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? show_equation.append("*");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
?
? ? ? ? div.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? //判斷用戶是否輸入了內容
? ? ? ? ? ? ? ? if(!(show_equation.toString().equals(""))&&!(show_equation.toString().equals("錯誤"))) {
? ? ? ? ? ? ? ? ? ? signal=0;
? ? ? ? ? ? ? ? ? ? char temp=show_equation.charAt(show_equation.length()-1);
? ? ? ? ? ? ? ? ? ? if(temp=='+'||temp=='-'||temp=='*'||temp=='/')
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? show_equation.deleteCharAt(show_equation.length()-1);
? ? ? ? ? ? ? ? ? ? ? ? show_equation.append("/");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? show_equation.append("/");
? ? ? ? ? ? ? ? ? ? result.setText(show_equation);
? ? ? ? ? ? ? ? ? ? result.setSelection(result.getText().length());
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? }
? ? protected boolean operatorPriorityCompare(char operator1,char operator2)
? ? {
? ? ? ? int o1=0;
? ? ? ? int o2=0;
? ? ? ? switch (operator1){
? ? ? ? ? ? case '+':{o1=0;break;}
? ? ? ? ? ? case '-':{o1=0;break;}
? ? ? ? ? ? case '*':{o1=1;break;}
? ? ? ? ? ? case '/':{o1=1;break;}
? ? ? ? }
? ? ? ? switch (operator2){
? ? ? ? ? ? case '+':{o2=0;break;}
? ? ? ? ? ? case '-':{o2=0;break;}
? ? ? ? ? ? case '*':{o2=1;break;}
? ? ? ? ? ? case '/':{o2=1;break;}
? ? ? ? }
? ? ? ? if(o1<=o2)
? ? ? ? {
? ? ? ? ? ? return false;
? ? ? ? }
? ? ? ? else
? ? ? ? ? ? return true;
? ? }
? ? //相加
? ? public static Double Add(Double d1,Double d2) {
? ? ? ? if(d1==Double.NEGATIVE_INFINITY||d1==Double.POSITIVE_INFINITY||d2==Double.NEGATIVE_INFINITY||d2==Double.POSITIVE_INFINITY){
? ? ? ? ? ? return d1+d2;
? ? ? ? }
? ? ? ? if(String.valueOf(d1).equals("NaN")||String.valueOf(d1).equals("NaN")){
? ? ? ? ? ? //如果兩個運算數(shù)只要有一個是非數(shù)'NaN',就直接運算即可
? ? ? ? ? ? return d1+d2;
? ? ? ? }
? ? ? ? //BigDecimal為精確計算的一個數(shù)據(jù)類型,你可以理解為使用它進行計算結果將更準確
? ? ? ? BigDecimal b1 = new BigDecimal(Double.toString(d1));
? ? ? ? BigDecimal b2 = new BigDecimal(Double.toString(d2));
? ? ? ? //進行計算并將結果轉為double返回
? ? ? ? return b1.add(b2).doubleValue();
? ? }
? ? //相減
? ? public static Double Sub(Double d1,Double d2){
? ? ? ? if(d1==Double.NEGATIVE_INFINITY||d1==Double.POSITIVE_INFINITY||d2==Double.NEGATIVE_INFINITY||d2==Double.POSITIVE_INFINITY){
? ? ? ? ? ? return d1-d2;
? ? ? ? }
? ? ? ? if(String.valueOf(d1).equals("NaN")||String.valueOf(d1).equals("NaN")){
? ? ? ? ? ? return d1-d2;
? ? ? ? }
? ? ? ? if(String.valueOf(d1).equals("NaN")||String.valueOf(d1).equals("NaN")){
? ? ? ? ? ? return d1*d2;
? ? ? ? }
? ? ? ? BigDecimal b1=new BigDecimal(Double.toString(d1));
? ? ? ? BigDecimal b2=new BigDecimal(Double.toString(d2));
? ? ? ? return b1.subtract(b2).doubleValue();
? ? }
? ? //相乘
? ? public static Double Mul(Double d1,Double d2){
? ? ? ? if(d1==Double.NEGATIVE_INFINITY||d1==Double.POSITIVE_INFINITY||d2==Double.NEGATIVE_INFINITY||d2==Double.POSITIVE_INFINITY){
? ? ? ? ? ? return d1*d2;
? ? ? ? }
? ? ? ? if(String.valueOf(d1).equals("NaN")||String.valueOf(d1).equals("NaN")){
? ? ? ? ? ? return d1*d2;
? ? ? ? }
? ? ? ? BigDecimal b1=new BigDecimal(Double.toString(d1));
? ? ? ? BigDecimal b2=new BigDecimal(Double.toString(d2));
? ? ? ? return b1.multiply(b2).setScale(8).doubleValue();
? ? }
? ? //相除
? ? public static Double Div(Double d1,Double d2){
? ? ? ? if(d1==Double.NEGATIVE_INFINITY||d1==Double.POSITIVE_INFINITY||d2==Double.NEGATIVE_INFINITY||d2==Double.POSITIVE_INFINITY){
? ? ? ? ? ? return d1/d2;
? ? ? ? }
? ? ? ? if(String.valueOf(d1).equals("NaN")||String.valueOf(d1).equals("NaN")){
? ? ? ? ? ? return d1/d2;
? ? ? ? }
? ? ? ? if(d1==0.0&&d2==0.0){
? ? ? ? ? ? return Double.NaN;
? ? ? ? }
? ? ? ? if(d2==0.0){
? ? ? ? ? ? return d1/d2;
? ? ? ? }
? ? ? ? BigDecimal b1=new BigDecimal(Double.toString(d1));
? ? ? ? BigDecimal b2=new BigDecimal(Double.toString(d2));
? ? ? ? return b1.divide(b2,8,BigDecimal.ROUND_HALF_UP).doubleValue();
? ? }
? ? //這個方法就是用來計算結果的,在344行被調用,參數(shù)為計算式
? ? //里面過程比較復雜,你需先弄懂后綴表達式,然后可對照理解大概流程意思即可
? ? protected String calculate(ArrayList equation){
? ? ? ? Double temp2;
? ? ? ? Double temp3;
? ? ? ? Double result;
? ? ? ? List operator=new ArrayList();
? ? ? ? List<Double> operand=new ArrayList();
? ? ? ? for(int i=0;i<equation.size();i++)
? ? ? ? {
? ? ? ? ? ? String temp4=(String) equation.get(i);
? ? ? ? ? ? if(temp4.equals("+")||temp4.equals("-")||temp4.equals("*")||temp4.equals("/"))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if(operator.size()>0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? String temp5=operator.get(operator.size()-1).toString();
? ? ? ? ? ? ? ? ? ? while(!(operatorPriorityCompare(temp4.charAt(0),temp5.charAt(0)))&&operator.size()>0)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? operator.remove(operator.size()-1);
? ? ? ? ? ? ? ? ? ? ? ? temp3=operand.get(operand.size()-1);
? ? ? ? ? ? ? ? ? ? ? ? operand.remove(operand.size()-1);
? ? ? ? ? ? ? ? ? ? ? ? temp2=operand.get(operand.size()-1);
? ? ? ? ? ? ? ? ? ? ? ? operand.remove(operand.size()-1);
? ? ? ? ? ? ? ? ? ? ? ? switch (temp5.charAt(0)){
? ? ? ? ? ? ? ? ? ? ? ? ? ? case '+':{result=Add(temp2,temp3);operand.add(result);break;}
? ? ? ? ? ? ? ? ? ? ? ? ? ? case '-':{result=Sub(temp2,temp3);operand.add(result);break;}
? ? ? ? ? ? ? ? ? ? ? ? ? ? case '*':{result=Mul(temp2,temp3);operand.add(result);break;}
? ? ? ? ? ? ? ? ? ? ? ? ? ? case '/':{result=Div(temp2,temp3);operand.add(result);break;}
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? if(operator.size()>0)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? temp5=operator.get(operator.size()-1).toString();
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? operator.add(temp4);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? operator.add(temp4);
? ? ? ? ? ? }
? ? ? ? ? ? else if(temp4.equals("#"))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? while(operator.size()>0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? String temp6=(String)operator.get(operator.size()-1);
? ? ? ? ? ? ? ? ? ? operator.remove(operator.size()-1);
? ? ? ? ? ? ? ? ? ? temp3=operand.get(operand.size()-1);
? ? ? ? ? ? ? ? ? ? operand.remove(operand.size()-1);
? ? ? ? ? ? ? ? ? ? temp2=operand.get(operand.size()-1);
? ? ? ? ? ? ? ? ? ? operand.remove(operand.size()-1);
? ? ? ? ? ? ? ? ? ? switch (temp6.charAt(0)){
? ? ? ? ? ? ? ? ? ? ? ? case '+':{result=Add(temp2,temp3);operand.add(result);break;}
? ? ? ? ? ? ? ? ? ? ? ? case '-':{result=Sub(temp2,temp3);operand.add(result);break;}
? ? ? ? ? ? ? ? ? ? ? ? case '*':{result=Mul(temp2,temp3);operand.add(result);break;}
? ? ? ? ? ? ? ? ? ? ? ? case '/':{result=Div(temp2,temp3);operand.add(result);break;}
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if(temp4.equals("NaN")){
? ? ? ? ? ? ? ? ? ? operand.add(Double.NaN);
? ? ? ? ? ? ? ? }else if(temp4.equals("∞")){
? ? ? ? ? ? ? ? ? ? operand.add(Double.POSITIVE_INFINITY);
? ? ? ? ? ? ? ? }else if(temp4.equals(".")){
? ? ? ? ? ? ? ? ? ? return "錯誤";
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? operand.add(Double.parseDouble(temp4));
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? if(operand.get(0)==Double.NEGATIVE_INFINITY) return "-∞";
? ? ? ? if(operand.get(0)==Double.POSITIVE_INFINITY) return "∞";
? ? ? ? return operand.get(0).toString();
? ? }
? ? //當API最低版小于21時使用這個函數(shù)實現(xiàn)點擊文本框不彈出鍵盤
? ? public void disableShowInput(EditText et) {
? ? ? ? Class<EditText> cls = EditText.class;
? ? ? ? Method method;
? ? ? ? try {
? ? ? ? ? ? method = cls.getMethod("setShowSoftInputOnFocus", boolean.class);
? ? ? ? ? ? method.setAccessible(true);
? ? ? ? ? ? method.invoke(et, false);
? ? ? ? } catch (Exception e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? }
? ? }
}

buttonstytle.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
? ? <!-- 主體背景顏色值 -->
? ? <solid android:color="#666666" />
? ? <!-- 連框寬度和顏色值 -->
? ? <stroke
? ? ? ? android:width="0.01dp"
? ? ? ? android:color="#FFFFFF" />
</shape>

activity_main.xml

<?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="match_parent"
? ? android:orientation="vertical">
?
? ? <!--鑲嵌一個標題欄-->
?
? ? <EditText
? ? ? ? android:id="@+id/result"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:singleLine="true"
? ? ? ? android:textSize="40sp" />
?
? ? <LinearLayout
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="0dp"
? ? ? ? android:layout_weight="1"
? ? ? ? android:orientation="horizontal">
?
? ? ? ? <Button
? ? ? ? ? ? android:id="@+id/cls"
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:background="@drawable/buttonstytle"
? ? ? ? ? ? android:text="C"
? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? android:textSize="20sp" />
?
? ? ? ? <Button
? ? ? ? ? ? android:id="@+id/div"
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:background="@drawable/buttonstytle"
? ? ? ? ? ? android:text="/"
? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? android:textSize="20sp" />
?
? ? ? ? <Button
? ? ? ? ? ? android:id="@+id/mul"
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:background="@drawable/buttonstytle"
? ? ? ? ? ? android:text="*"
? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? android:textSize="20sp" />
?
? ? ? ? <Button
? ? ? ? ? ? android:id="@+id/Backspace"
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:background="@drawable/buttonstytle"
? ? ? ? ? ? android:text="Backspace"
? ? ? ? ? ? android:textAllCaps="false"
? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? android:textSize="20sp" />
? ? </LinearLayout>
?
? ? <LinearLayout
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="0dp"
? ? ? ? android:layout_weight="1"
? ? ? ? android:orientation="horizontal">
?
? ? ? ? <Button
? ? ? ? ? ? android:id="@+id/seven"
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:background="@drawable/buttonstytle"
? ? ? ? ? ? android:text="7"
? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? android:textSize="20sp" />
?
? ? ? ? <Button
? ? ? ? ? ? android:id="@+id/eight"
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:background="@drawable/buttonstytle"
? ? ? ? ? ? android:text="8"
? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? android:textSize="20sp" />
?
? ? ? ? <Button
? ? ? ? ? ? android:id="@+id/nine"
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:background="@drawable/buttonstytle"
? ? ? ? ? ? android:text="9"
? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? android:textSize="20sp" />
?
? ? ? ? <Button
? ? ? ? ? ? android:id="@+id/sub"
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:background="@drawable/buttonstytle"
? ? ? ? ? ? android:text="-"
? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? android:textSize="20sp" />
? ? </LinearLayout>
?
? ? <LinearLayout
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="0dp"
? ? ? ? android:layout_weight="1"
? ? ? ? android:orientation="horizontal">
?
? ? ? ? <Button
? ? ? ? ? ? android:id="@+id/four"
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:background="@drawable/buttonstytle"
? ? ? ? ? ? android:text="4"
? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? android:textSize="20sp" />
?
? ? ? ? <Button
? ? ? ? ? ? android:id="@+id/five"
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:background="@drawable/buttonstytle"
? ? ? ? ? ? android:text="5"
? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? android:textSize="20sp" />
?
? ? ? ? <Button
? ? ? ? ? ? android:id="@+id/six"
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:background="@drawable/buttonstytle"
? ? ? ? ? ? android:text="6"
? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? android:textSize="20sp" />
?
? ? ? ? <Button
? ? ? ? ? ? android:id="@+id/add"
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:background="@drawable/buttonstytle"
? ? ? ? ? ? android:text="+"
? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? android:textSize="20sp" />
? ? </LinearLayout>
?
? ? <LinearLayout
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="0dp"
? ? ? ? android:layout_weight="2"
? ? ? ? android:orientation="horizontal">
?
? ? ? ? <LinearLayout
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:orientation="vertical">
?
? ? ? ? ? ? <LinearLayout
? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? android:layout_height="1dp"
? ? ? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? ? ? android:orientation="horizontal">
?
? ? ? ? ? ? ? ? <Button
? ? ? ? ? ? ? ? ? ? android:id="@+id/one"
? ? ? ? ? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? ? ? ? ? android:background="@drawable/buttonstytle"
? ? ? ? ? ? ? ? ? ? android:text="1"
? ? ? ? ? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? ? ? ? ? android:textSize="20sp" />
?
? ? ? ? ? ? ? ? <Button
? ? ? ? ? ? ? ? ? ? android:id="@+id/two"
? ? ? ? ? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? ? ? ? ? android:background="@drawable/buttonstytle"
? ? ? ? ? ? ? ? ? ? android:text="2"
? ? ? ? ? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? ? ? ? ? android:textSize="20sp" />
? ? ? ? ? ? </LinearLayout>
?
? ? ? ? ? ? <LinearLayout
? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? android:layout_height="1dp"
? ? ? ? ? ? ? ? android:layout_weight="1">
?
? ? ? ? ? ? ? ? <Button
? ? ? ? ? ? ? ? ? ? android:id="@+id/zero"
? ? ? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? ? ? ? ? android:background="@drawable/buttonstytle"
? ? ? ? ? ? ? ? ? ? android:text="0"
? ? ? ? ? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? ? ? ? ? android:textSize="20sp" />
? ? ? ? ? ? </LinearLayout>
? ? ? ? </LinearLayout>
?
? ? ? ? <LinearLayout
? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? android:orientation="horizontal">
?
? ? ? ? ? ? <LinearLayout
? ? ? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? ? ? android:orientation="vertical">
?
? ? ? ? ? ? ? ? <Button
? ? ? ? ? ? ? ? ? ? android:id="@+id/three"
? ? ? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? ? ? android:layout_height="1dp"
? ? ? ? ? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? ? ? ? ? android:background="@drawable/buttonstytle"
? ? ? ? ? ? ? ? ? ? android:text="3"
? ? ? ? ? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? ? ? ? ? android:textSize="20sp" />
?
? ? ? ? ? ? ? ? <Button
? ? ? ? ? ? ? ? ? ? android:id="@+id/spot"
? ? ? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? ? ? android:layout_height="1dp"
? ? ? ? ? ? ? ? ? ? android:layout_weight="1"
? ? ? ? ? ? ? ? ? ? android:background="@drawable/buttonstytle"
? ? ? ? ? ? ? ? ? ? android:text="."
? ? ? ? ? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? ? ? ? ? android:textSize="20sp" />
? ? ? ? ? ? </LinearLayout>
?
? ? ? ? ? ? <LinearLayout
? ? ? ? ? ? ? ? android:layout_width="0dp"
? ? ? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? ? ? android:layout_weight="1">
?
? ? ? ? ? ? ? ? <Button
? ? ? ? ? ? ? ? ? ? android:id="@+id/equal"
? ? ? ? ? ? ? ? ? ? android:layout_width="match_parent"
? ? ? ? ? ? ? ? ? ? android:layout_height="match_parent"
? ? ? ? ? ? ? ? ? ? android:background="@drawable/buttonstytle"
? ? ? ? ? ? ? ? ? ? android:text="="
? ? ? ? ? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? ? ? ? ? android:textSize="20sp" />
? ? ? ? ? ? </LinearLayout>
? ? ? ? </LinearLayout>
? ? </LinearLayout>
</LinearLayout>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論