ODE_DPAD_LEFT: /* keyCode=21 */ MoveButtonLeft(); break; /* 右按键 */ case KeyEvent.KEYCODE_DPAD_RIGHT: /* keyCode=22 */ MoveButtonRight(); break; } return super.onKeyDown(keyCode, event); } /* 还原按钮位置的事件处理 */ public void RestoreButton() { intButtonX = ((intScreenX-intWidth)/2); intButtonY = ((intScreenY-intHeight)/2); mMakeTextToast ( "("+Integer.toString(intButtonX)+ ","+Integer.toString(intButtonY)+")",true ); mButton01.setLayoutParams ( // AbsoluteLayout.LayoutParams已被[deprecated] new AbsoluteLayout.LayoutParams ( intWidth,intHeight,intButtonX,intButtonY ) ); } /* 按下D-Pad上按键时事件处理 */ public void MoveButtonUp() { intButtonY = intButtonY-intShift; if(intButtonY<0) { intButtonY = 0; } mButton01.setLayoutParams ( new AbsoluteLayout.LayoutParams ( intWidth,intHeight,intButtonX,intButtonY ) ); } /* 按下D-Pad下按键时事件处理 */ public void MoveButtonDown() { intButtonY = intButtonY+intShift; if(intButtonY>(intScreenY-intHeight)) { intButtonY = intScreenY-intHeight; } mButton01.setLayoutParams ( new AbsoluteLayout.LayoutParams ( intWidth,intHeight,intButtonX,intButtonY ) ); } /* 按下D-Pad左按键时事件处理 */ public void MoveButtonLeft() { intButtonX = intButtonX-intShift; if(intButtonX<0) { intButtonX = 0; } mButton01.setLayoutParams ( new AbsoluteLayout.LayoutParams ( intWidth,intHeight,intButtonX,intButtonY ) ); } /* 按下D-Pad右按键时事件处理 */ public void MoveButtonRight() { intButtonX = intButtonX+intShift; if(intButtonX>(intScreenX-intWidth)) { intButtonX = intScreenX-intWidth; } mButton01.setLayoutParams ( new AbsoluteLayout.LayoutParams ( intWidth,intHeight,intButtonX,intButtonY ) ); } public void mMakeTextToast(String str, boolean isLong) { if(isLong==true) { Toast.makeText(EX05_20.this, str, Toast.LENGTH_LONG).show(); } else { Toast.makeText(EX05_20.this, str, Toast.LENGTH_SHORT).show(); } }}