Android实现简单的Calc

DifferentSeasons_Y 发布于 2015/01/09 14:25
阅读 638
收藏 3

一个简单的计算机apk,实现基本的+ - * /功能,实现一个较为美观的布局;

代码分三部分:

1.布局代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
	<!-- 整个页面布局为:RelativeLayout为总布局,内部包括2个RelativeLayout相对布局,在该布局下方放入一个LinearLayout线性布局(android:orientation="horizontal");
	该线性布局内部放入4个线性布局(android:orientation="vertical");这中间我碰到了一个问题,就是让ImageView充满屏幕时,Text属性的内容字数多,则会
	把这个大View撑开,暂时未想到好的解决办法。
	 -->
	 <!-- 
	 Android开发,布局控制方面是一个难点,在这我解释一下两种布局不同属性的意义:
	 RelativeLayout:
	 				layout_alignParentTop="true" 贴紧父元素的上边缘
	 				layout_centerHorizontal="true" 将该控件的置于水平居中
	 				layout_marginLeft="15dp" 左偏移的值
	 TextView:		
	 				layout_alignParentBottom="true" 贴紧父元素的下边缘
	 				layout_alignParentRight="true"
	 				android:textColor="#FFFFFF"	设置文本颜色
	 LinearLayout:				
	 				android:layout_below="@+id/relativeL2" 贴紧relativeL2的下边缘
			        android:layout_marginBottom="20dp"
			        android:layout_marginLeft="10dp" 左偏移的值
			        android:layout_marginRight="10dp"
			        android:layout_marginTop="20dp"
			        
			        
		           android:layout_width="wrap_content" 自然宽度
		           android:layout_height="match_parent" 自适应高
		           android:layout_weight="1" 宽度比例为1(该比例相对与父LinearLayout下其他view)
	  -->
    <RelativeLayout
        android:id="@+id/relativeL1"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="5dp" >

        <TextView
            android:id="@+id/num_calc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:text=""
            android:textColor="#FFFFFF" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativeL2"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_below="@+id/relativeL1"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="0dp" >

        <TextView
            android:id="@+id/num_result"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:text="0"
            android:textColor="#FFFFFF"
            android:textSize="30dp" />
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/linearL_zong"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/relativeL2"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="20dp"
        android:orientation="horizontal" >

        <LinearLayout
            android:id="@+id/linearL1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" >

            <Button
                android:id="@+id/calc_C"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#5d5e5b"
                android:text="C"
                android:textSize="20sp"
                android:textColor="#FFFFFF" />
            <Button
                android:id="@+id/calc_7"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#272827"
                android:textSize="20sp"
                android:text="7"
                android:textColor="#FFFFFF" />

            <Button
                android:id="@+id/calc_4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#272827"
                android:textSize="20sp"
                android:text="4"
                android:textColor="#FFFFFF" />

            <Button
                android:id="@+id/calc_1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#272827"
                android:textSize="20sp"
                android:text="1"
                android:textColor="#FFFFFF" />

            <Button
                android:id="@+id/calc_dian"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#5d5e5b"
                android:textSize="20sp"
                android:text=" ."
                android:textColor="#FFFFFF" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearL2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" >
            <Button
                android:id="@+id/calc_Y"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#5d5e5b"
                android:textSize="20sp"
                android:text="Y"
                android:textColor="#FFFFFF" />

            <Button
                android:id="@+id/calc_8"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#272827"
                android:textSize="20sp"
                android:text="8"
                android:textColor="#FFFFFF" />

            <Button
                android:id="@+id/calc_5"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#272827"
                android:textSize="20sp"
                android:text="5"
                android:textColor="#FFFFFF" />

            <Button
                android:id="@+id/calc_2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#272827"
                android:textSize="20sp"
                android:text="2"
                android:textColor="#FFFFFF" />

            <Button
                android:id="@+id/calc_0"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#5d5e5b"
                android:textSize="20sp"
                android:text="0"
                android:textColor="#FFFFFF" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearL3"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" >
            <Button
                android:id="@+id/calc_X"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#5d5e5b"
                android:textSize="20sp"
                android:text="X"
                android:textColor="#FFFFFF" />

            <Button
                android:id="@+id/calc_9"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#272827"
                android:textSize="20sp"
                android:text="9"
                android:textColor="#FFFFFF" />

            <Button
                android:id="@+id/calc_6"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#272827"
                android:textSize="20sp"
                android:text="6"
                android:textColor="#FFFFFF" />

            <Button
                android:id="@+id/calc_3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#272827"
                android:textSize="20sp"
                android:text="3"
                android:textColor="#FFFFFF" />

            <Button
                android:id="@+id/calc_result"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#5d5e5b"
                android:textSize="20sp"
                android:text="="
                android:textColor="#FFFFFF" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearL4"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" >

            <Button
                android:id="@+id/calc_del"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#5d5e5b"
                android:textSize="20sp"
                android:text="DEL"
                android:textColor="#FFFFFF" />
            <Button
                android:id="@+id/calc_chu"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#5d5e5b"
                android:textSize="20sp"
                android:text="/"
                android:textColor="#FFFFFF" />

            <Button
                android:id="@+id/calc_cheng"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#5d5e5b"
                android:textSize="20sp"
                android:text="*"
                android:textColor="#FFFFFF" />

            <Button
                android:id="@+id/calc_add"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#5d5e5b"
                android:textSize="20sp"
                android:text="+"
                android:textColor="#FFFFFF" />

            <Button
                android:id="@+id/calc_jian"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="#5d5e5b"
                android:textSize="20sp"
                android:text="-"
                android:textColor="#FFFFFF" />
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>



2.Activity.java

//操作
private Button calc_0;
private Button calc_1;
private Button calc_2;
private Button calc_3;
private Button calc_4;
private Button calc_5;
private Button calc_6;
private Button calc_7;
private Button calc_8;
private Button calc_9;
private Button calc_dian;
private Button calc_add;
private Button calc_jian;
private Button calc_cheng;
private Button calc_chu;
private Button calc_result;
private Button calc_C;
private Button calc_del;
//显示公式
private TextView num_calc;
//显示计算结果
private TextView num_result;
//标记
private int tag = 1;
//
private String lastResult = "0";
private String YUNSUAN_TAG = "";


MCCalc mcc = new MCCalc();

@Override
protected void onResume() {
	// TODO Auto-generated method stub
super.onResume();

calc_0 = (Button)findViewById(R.id.calc_0);
calc_1 = (Button)findViewById(R.id.calc_1);
calc_2 = (Button)findViewById(R.id.calc_2);
calc_3 = (Button)findViewById(R.id.calc_3);
calc_4 = (Button)findViewById(R.id.calc_4);
calc_5 = (Button)findViewById(R.id.calc_5);
calc_6 = (Button)findViewById(R.id.calc_6);
calc_7 = (Button)findViewById(R.id.calc_7);
calc_8 = (Button)findViewById(R.id.calc_8);
calc_9 = (Button)findViewById(R.id.calc_9);
calc_dian = (Button)findViewById(R.id.calc_dian);
calc_add = (Button)findViewById(R.id.calc_add);
calc_result = (Button)findViewById(R.id.calc_result);
calc_jian = (Button)findViewById(R.id.calc_jian);
calc_cheng = (Button)findViewById(R.id.calc_cheng);
calc_chu = (Button)findViewById(R.id.calc_chu);
calc_C = (Button)findViewById(R.id.calc_C);
calc_del = (Button)findViewById(R.id.calc_del);

calc_del.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		num_result = (TextView)findViewById(R.id.num_result);
		String temp = num_result.getText().toString();
		num_result.setText(temp.substring(0, temp.length()-1));
	}
});
calc_C.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		num_result = (TextView)findViewById(R.id.num_result);
		num_calc = (TextView)findViewById(R.id.num_calc);
		num_result.setText("0");
		num_calc.setText("");
		YUNSUAN_TAG = "";
		lastResult = "0";
		tag = 1;
	}
});
calc_result.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		num_result = (TextView)findViewById(R.id.num_result);
		num_calc = (TextView)findViewById(R.id.num_calc);
		num_result.setText(mcc.resultCalc(lastResult,num_result.getText().toString(),YUNSUAN_TAG)+"");
		num_calc.setText("");
		YUNSUAN_TAG = "";
	}
});
calc_chu.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		num_result = (TextView)findViewById(R.id.num_result);
		num_calc = (TextView)findViewById(R.id.num_calc);

		lastResult = mcc.resultCalc(lastResult,num_result.getText().toString(), YUNSUAN_TAG)+"";			
		//点+,给num_calc赋值,将num_result清空;
		YUNSUAN_TAG = "/";
		num_calc.setText(num_calc.getText().toString()+num_result.getText().toString()+YUNSUAN_TAG);
		num_result.setText(lastResult);
		tag = -1;
	}
});
calc_cheng.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		num_result = (TextView)findViewById(R.id.num_result);
		num_calc = (TextView)findViewById(R.id.num_calc);

		lastResult = mcc.resultCalc(lastResult,num_result.getText().toString(), YUNSUAN_TAG)+"";			
		//点+,给num_calc赋值,将num_result清空;
		YUNSUAN_TAG = "*";
		num_calc.setText(num_calc.getText().toString()+num_result.getText().toString()+YUNSUAN_TAG);
		num_result.setText(lastResult);
		tag = -1;
	}
});
calc_jian.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		num_result = (TextView)findViewById(R.id.num_result);
		num_calc = (TextView)findViewById(R.id.num_calc);

		lastResult = mcc.resultCalc(lastResult,num_result.getText().toString(), YUNSUAN_TAG)+"";			
		//点+,给num_calc赋值,将num_result清空;
		YUNSUAN_TAG = "-";
		num_calc.setText(num_calc.getText().toString()+num_result.getText().toString()+YUNSUAN_TAG);
		num_result.setText(lastResult);
		tag = -1;
	}
});
calc_add.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		num_result = (TextView)findViewById(R.id.num_result);
		num_calc = (TextView)findViewById(R.id.num_calc);

		lastResult = mcc.resultCalc(lastResult,num_result.getText().toString(), YUNSUAN_TAG)+"";
		//点+,给num_calc赋值,将num_result清空;
		YUNSUAN_TAG = "+";
		num_calc.setText(num_calc.getText().toString()+num_result.getText().toString()+YUNSUAN_TAG);
		num_result.setText(lastResult);
		tag = -1;
	}
});
calc_dian.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		num_result = (TextView)findViewById(R.id.num_result);
		String temp_input = num_result.getText().toString();
		String temp = calc_dian.getText().toString();
		temp = temp.substring(1, 2);
		//如果第一个数字是0,需要处理
		if(temp_input.equals("0")&&temp_input.length()==1){
			num_result.setText(temp_input+temp);
			return;
		}
		num_result.setText(temp_input+temp);
	}
});
calc_0.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		num_result = (TextView)findViewById(R.id.num_result);
		if(tag==-1){
			num_result.setText("");
			tag = 1;
		}
		String temp_input = num_result.getText().toString();
		//如果第一个数字是0,需要处理
		if(temp_input.equals("0")&&temp_input.length()==1){
			return;
		}
		num_result.setText(temp_input+calc_0.getText());
	}
});
calc_1.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		num_result = (TextView)findViewById(R.id.num_result);
		if(tag==-1){
			num_result.setText("");
			tag = 1;
		}
		String temp_input = num_result.getText().toString(); 
		if(temp_input.equals("0")&&temp_input.length()==1){
			num_result.setText(calc_1.getText());
			return;
		}
		num_result.setText(temp_input+calc_1.getText());
	}
});
calc_2.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		num_result = (TextView)findViewById(R.id.num_result);
		if(tag==-1){
			num_result.setText("");
			tag = 1;
		}
		String temp_input = num_result.getText().toString(); 
		if(temp_input.equals("0")&&temp_input.length()==1){
			num_result.setText(calc_2.getText());
			return;
		}
		num_result.setText(temp_input+calc_2.getText());
	}
});
calc_3.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		num_result = (TextView)findViewById(R.id.num_result);
		if(tag==-1){
			num_result.setText("");
			tag = 1;
		}
		String temp_input = num_result.getText().toString(); 
		if(temp_input.equals("0")&&temp_input.length()==1){
			num_result.setText(calc_3.getText());
			return;
		}
		num_result.setText(temp_input+calc_3.getText());
	}
});
calc_4.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		num_result = (TextView)findViewById(R.id.num_result);
		if(tag==-1){
			num_result.setText("");
			tag = 1;
		}
		String temp_input = num_result.getText().toString(); 
		if(temp_input.equals("0")&&temp_input.length()==1){
			num_result.setText(calc_4.getText());
			return;
		}
		num_result.setText(temp_input+calc_4.getText());
	}
});
calc_5.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		num_result = (TextView)findViewById(R.id.num_result);
		if(tag==-1){
			num_result.setText("");
			tag = 1;
		}
		String temp_input = num_result.getText().toString(); 
		if(temp_input.equals("0")&&temp_input.length()==1){
			num_result.setText(calc_5.getText());
			return;
		}
		num_result.setText(temp_input+calc_5.getText());
	}
});
calc_6.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		num_result = (TextView)findViewById(R.id.num_result);
		if(tag==-1){
			num_result.setText("");
			tag = 1;
		}
		String temp_input = num_result.getText().toString(); 
		if(temp_input.equals("0")&&temp_input.length()==1){
			num_result.setText(calc_6.getText());
			return;
		}
		num_result.setText(temp_input+calc_6.getText());
	}
});
calc_7.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		num_result = (TextView)findViewById(R.id.num_result);
		if(tag==-1){
			num_result.setText("");
			tag = 1;
		}
		String temp_input = num_result.getText().toString(); 
		if(temp_input.equals("0")&&temp_input.length()==1){
			num_result.setText(calc_7.getText());
			return;
		}
		num_result.setText(temp_input+calc_7.getText());
	}
});
calc_8.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		num_result = (TextView)findViewById(R.id.num_result);
		if(tag==-1){
			num_result.setText("");
			tag = 1;
		}
		String temp_input = num_result.getText().toString(); 
		if(temp_input.equals("0")&&temp_input.length()==1){
			num_result.setText(calc_8.getText());
			return;
		}
		num_result.setText(temp_input+calc_8.getText());
	}
});
calc_9.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		num_result = (TextView)findViewById(R.id.num_result);
		if(tag==-1){
			num_result.setText("");
			tag = 1;
		}
		String temp_input = num_result.getText().toString(); 
		if(temp_input.equals("0")&&temp_input.length()==1){
				num_result.setText(calc_9.getText());
				return;
			}
			num_result.setText(temp_input+calc_9.getText());
		}
	});
	
	
}



3.逻辑层代码

public double chuCalc(double x,double y,String tag){
	//x+y=z
	return x/y;
}
public double chengCalc(double x,double y,String tag){
	//x+y=z
	return x*y;
}
public double jianCalc(double x,double y,String tag){
	//x+y=z
	if(x==0){
		return y;
	}
	return x-y;
}
public double addCalc(double x,double y,String tag){
	//x+y=z
	return x+y;
}
public double resultCalc(String result,String lastResult,String tag){
	//x+y=z
	double x = Double.parseDouble(result);
	double y = Double.parseDouble(lastResult);
//		System.out.println("--:"+x+tag+y+"=");
	double z = y;
	if(tag.equals("+")){
		z = addCalc(x,y,"+");
	}
	if(tag.equals("-")){
		z = jianCalc(x,y,"-");
	}
	if(tag.equals("*")){
		z = chengCalc(x,y,"*");
	}
	if(tag.equals("/")){
		z = chuCalc(x,y,"/");
	}
	return z;
}



注意:1.如果您运行了这段代码,会发现,计算器的按钮第四列比前三列宽,我使用了1:1:1:1的线性布局,但是效果却被Text属性的文字个数给打破,具体解决办法,在探究中。

2.以上代码仅供参考,如有不足之处请直接指出,小弟一定膜拜学习~~~

以下是话题补充:

@DifferentSeasons_Y:注意:1.提出的问题已经解决,暂时不公布解决方案,大家可以思考一下,留言给我,我会提供解决办法。 (2015/01/09 14:41)
加载中
0
espilce
espilce
layout和style多提炼一点出来比较好
0
DifferentSeasons_Y
DifferentSeasons_Y

引用来自“espilce”的评论

layout和style多提炼一点出来比较好
感谢您的宝贵意见,想了好久才做了这样的设计,如果您有什么好的建议,希望能够告诉我,我好学习一下。
0
KingBright
KingBright
KingBright
回复 @Y_ai : 哦,前面多了个http:// 那个地址可能需要代理或者vpn 用这个地址试试https://github.com/android/platform_packages_apps_calculator
DifferentSeasons_Y
DifferentSeasons_Y
地址打不开
返回顶部
顶部