废话不多说了,一切尽在代码中,具体代码如下所示:
界面
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff808080"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cursorVisible="false"
android:gravity="right"
android:editable = "false"
android:text="0" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
android:layout_width="53sp"
android:layout_height="wrap_content"
android:text=" MEM :" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="0" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
android:layout_width="53sp"
android:layout_height="wrap_content"
android:text=" DEG" />
android:text="MC"
android:layout_width="106sp"
android:layout_height="wrap_content" />
android:text="C"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
android:text="DRG"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="sin"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="cos"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="tan"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="n!"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="Bksp"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
android:text="7"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="8"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="9"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="÷"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="("
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text=")"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
android:text="4"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="5"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="6"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="×"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="√"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="^"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
android:text="1"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="2"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="3"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="-"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="log"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="ln"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:layout_width="fill_parent"
android:layout_height="57sp"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
android:text="0"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="."
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="="
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="+"
android:layout_width="53sp"
android:layout_height="wrap_content" />
android:text="exit"
android:layout_width="106sp"
android:layout_height="wrap_content" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
android:layout_width="60sp"
android:layout_height="wrap_content"
android:text="reminder:" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="欢迎使用!-www.javaapk.com 提供源码" />
代码
package com.example.yanlei.mytk;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher;
import java.text.DecimalFormat;
import java.util.StringTokenizer;
import android.os.Bundle;
import android.R.integer;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
// 定义变量
private Button[] btn = new Button[10];// 0~9十个数字
private EditText input;// 用于显示输出结果
private TextView mem, _drg, tip;
private Button div, mul, sub, add, equal, sin, cos, tan, log, ln, sqrt,
square, factorial, bksp, left, right, dot, exit, drg, mc, c;
public String str_old;
public String str_new;
public boolean vbegin = true;// 控制输入,true为重新输入,false为接着输入
public boolean drg_flag = true;// true为角度,false为弧度
public double pi = 4 * Math.atan(1);// π值
public boolean tip_lock = true;// true为正确,可以继续输入,false错误,输入锁定
public boolean equals_flag = true;// 是否在按下=之后输入,true为之前,false为之后
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
InitWigdet();
AllWigdetListener();
}
<