这是代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DecimalFormat currencyFormatter = (DecimalFormat)NumberFormat.getInstance();
char decimalSeparator = currencyFormatter.getDecimalFormatSymbols().getDecimalSeparator();
mDecimalSeparator = Character.toString(decimalSeparator);
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
int Orientation = getResources().getConfiguration().orientation;
if(Orientation == Configuration.ORIENTATION_PORTRAIT)
{
Button btn1 = (Button) findViewById(R.id.button1);
btn1.setLayoutParams(new LayoutParams(height/9,width/6));
Button btn2 = (Button) findViewById(R.id.button2);
btn2.setLayoutParams(new LayoutParams(height/9,width/6));
Button btn3 = (Button) findViewById(R.id.button3);
btn3.setLayoutParams(new LayoutParams(height/9,width/6));
Button btn4 = (Button) findViewById(R.id.button4);
btn4.setLayoutParams(new LayoutParams(height/9,width/6));
Button btn5 = (Button) findViewById(R.id.button5);
btn5.setLayoutParams(new LayoutParams(height/9,width/6));
Button btn6 = (Button) findViewById(R.id.button6);
btn6.setLayoutParams(new LayoutParams(height/9,width/6));
Button btn7 = (Button) findViewById(R.id.button7);
btn7.setLayoutParams(new LayoutParams(height/9,width/6));
Button btn8 = (Button) findViewById(R.id.button8);
btn8.setLayoutParams(new LayoutParams(height/9,width/6));
Button btn9 = (Button) findViewById(R.id.button9);
btn9.setLayoutParams(new LayoutParams(height/9,width/6));
Button btn0 = (Button) findViewById(R.id.button0);
btn0.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnadd = (Button) findViewById(R.id.buttonAdd);
btnadd.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnclrall = (Button) findViewById(R.id.buttonClearAll);
btnclrall.setLayoutParams(new LayoutParams(height/9,width/6));
Button btncos = (Button) findViewById(R.id.buttonCos);
btncos.setLayoutParams(new LayoutParams(height/9,width/6));
Button btncosinverse = (Button) findViewById(R.id.buttonCosInverse);
btncosinverse.setLayoutParams(new LayoutParams(height/9,width/6));
Button btndel = (Button) findViewById(R.id.buttonDel);
btndel.setLayoutParams(new LayoutParams(height/9,width/6));
Button btndivide = (Button) findViewById(R.id.buttonDivide);
btndivide.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnequal = (Button) findViewById(R.id.buttonEqual);
btnequal.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnfactorial = (Button) findViewById(R.id.buttonFactorial);
btnfactorial.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnlog10 = (Button) findViewById(R.id.buttonLog10);
btnlog10.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnloge = (Button) findViewById(R.id.buttonLoge);
btnloge.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnmadd = (Button) findViewById(R.id.buttonMAdd);
btnmadd.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnmc = (Button) findViewById(R.id.buttonMC);
btnmc.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnmr = (Button) findViewById(R.id.buttonMR);
btnmr.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnremove = (Button) findViewById(R.id.buttonMRemove);
btnremove.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnmultiply = (Button) findViewById(R.id.buttonMultiply);
btnmultiply.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnpercent = (Button) findViewById(R.id.buttonPercent);
btnpercent.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnperiod = (Button) findViewById(R.id.buttonPeriod);
btnperiod.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnpower = (Button) findViewById(R.id.buttonPower);
btnpower.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnsign = (Button) findViewById(R.id.buttonSign);
btnsign.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnsin = (Button) findViewById(R.id.buttonSin);
btnsin.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnsininverse = (Button) findViewById(R.id.buttonSinInverse);
btnsininverse.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnsquare = (Button) findViewById(R.id.buttonSquare);
btnsquare.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnsqrt = (Button) findViewById(R.id.buttonSquareRoot);
btnsqrt.setLayoutParams(new LayoutParams(height/9,width/6));
Button btnsubtract = (Button) findViewById(R.id.buttonSubtract);
btnsubtract.setLayoutParams(new LayoutParams(height/9,width/6));
Button btntan = (Button) findViewById(R.id.buttonTan);
btntan.setLayoutParams(new LayoutParams(height/9,width/6));
Button btntaninverse = (Button) findViewById(R.id.buttonTanInverse);
btntaninverse.setLayoutParams(new LayoutParams(height/9,width/6));
}
else
{
Button btn1 = (Button) findViewById(R.id.button1);
btn1.setLayoutParams(new LayoutParams(width/10,height/7));
Button btn2 = (Button) findViewById(R.id.button2);
btn2.setLayoutParams(new LayoutParams(width/10,height/7));
Button btn3 = (Button) findViewById(R.id.button3);
btn3.setLayoutParams(new LayoutParams(width/10,height/7));
Button btn4 = (Button) findViewById(R.id.button4);
btn4.setLayoutParams(new LayoutParams(width/10,height/7));
Button btn5 = (Button) findViewById(R.id.button5);
btn5.setLayoutParams(new LayoutParams(width/10,height/7));
Button btn6 = (Button) findViewById(R.id.button6);
btn6.setLayoutParams(new LayoutParams(width/10,height/7));
Button btn7 = (Button) findViewById(R.id.button7);
btn7.setLayoutParams(new LayoutParams(width/10,height/7));
Button btn8 = (Button) findViewById(R.id.button8);
btn8.setLayoutParams(new LayoutParams(width/10,height/7));
Button btn9 = (Button) findViewById(R.id.button9);
btn9.setLayoutParams(new LayoutParams(width/10,height/7));
Button btn0 = (Button) findViewById(R.id.button0);
btn0.setLayoutParams(new LayoutParams(width/10,height/7));
Button btnadd = (Button) findViewById(R.id.buttonAdd);
btnadd.setLayoutParams(new LayoutParams(width/10,height/7));
Button btnclrall = (Button) findViewById(R.id.buttonClearAll);
btnclrall.setLayoutParams(new LayoutParams(width/8,height/7));
Button btncos = (Button) findViewById(R.id.buttonCos);
btncos.setLayoutParams(new LayoutParams(width/8,height/7));
Button btncosinverse = (Button) findViewById(R.id.buttonCosInverse);
btncosinverse.setLayoutParams(new LayoutParams(width/8,height/7));
Button btndel = (Button) findViewById(R.id.buttonDel);
btndel.setLayoutParams(new LayoutParams(width/8,height/7));
Button btndivide = (Button) findViewById(R.id.buttonDivide);
btndivide.setLayoutParams(new LayoutParams(width/10,height/7));
Button btnequal = (Button) findViewById(R.id.buttonEqual);
btnequal.setLayoutParams(new LayoutParams(width/10,height/7));
Button btnfactorial = (Button) findViewById(R.id.buttonFactorial);
btnfactorial.setLayoutParams(new LayoutParams(width/8,height/7));
Button btnlog10 = (Button) findViewById(R.id.buttonLog10);
btnlog10.setLayoutParams(new LayoutParams(width/10,height/7));
Button btnloge = (Button) findViewById(R.id.buttonLoge);
btnloge.setLayoutParams(new LayoutParams(width/10,height/7));
Button btnmadd = (Button) findViewById(R.id.buttonMAdd);
btnmadd.setLayoutParams(new LayoutParams(width/8,height/7));
Button btnmc = (Button) findViewById(R.id.buttonMC);
btnmc.setLayoutParams(new LayoutParams(width/8,height/7));
Button btnmr = (Button) findViewById(R.id.buttonMR);
btnmr.setLayoutParams(new LayoutParams(width/8,height/7));
Button btnremove = (Button) findViewById(R.id.buttonMRemove);
btnremove.setLayoutParams(new LayoutParams(width/8,height/7));
Button btnmultiply = (Button) findViewById(R.id.buttonMultiply);
btnmultiply.setLayoutParams(new LayoutParams(width/10,height/7));
Button btnpercent = (Button) findViewById(R.id.buttonPercent);
btnpercent.setLayoutParams(new LayoutParams(width/10,height/7));
Button btnperiod = (Button) findViewById(R.id.buttonPeriod);
btnperiod.setLayoutParams(new LayoutParams(width/10,height/7));
Button btnpower = (Button) findViewById(R.id.buttonPower);
btnpower.setLayoutParams(new LayoutParams(width/8,height/7));
Button btnsign = (Button) findViewById(R.id.buttonSign);
btnsign.setLayoutParams(new LayoutParams(width/10,height/7));
Button btnsin = (Button) findViewById(R.id.buttonSin);
btnsin.setLayoutParams(new LayoutParams(width/8,height/7));
Button btnsininverse = (Button) findViewById(R.id.buttonSinInverse);
btnsininverse.setLayoutParams(new LayoutParams(width/8,height/7));
Button btnsquare = (Button) findViewById(R.id.buttonSquare);
btnsquare.setLayoutParams(new LayoutParams(width/8,height/7));
Button btnsqrt = (Button) findViewById(R.id.buttonSquareRoot);
btnsqrt.setLayoutParams(new LayoutParams(width/8,height/7));
Button btnsubtract = (Button) findViewById(R.id.buttonSubtract);
btnsubtract.setLayoutParams(new LayoutParams(width/10,height/7));
Button btntan = (Button) findViewById(R.id.buttonTan);
btntan.setLayoutParams(new LayoutParams(width/8,height/7));
Button btntaninverse = (Button) findViewById(R.id.buttonTanInverse);
btntaninverse.setLayoutParams(new LayoutParams(width/8,height/7));
}
以下是计算阶乘之前和之后我的应用程序的快照:
现在我计算了阶乘后,只显示了每行的第一个按钮,它完成了我的整个宽度: