我是 android 编程新手。我的代码需要帮助。如您所见,在单击使用 onDraw 方法和 onTouchEvent 制作的按钮后,我有一个菜单。
public boolean onTouchEvent(MotionEvent event)
{
CoordCheck cc = new CoordCheck();
Log.d(TAG, "Coords: X=" + event.getX() + ",Y=" + event.getY()+"choice="+glb.getChoice());
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
float x, y;
x = event.getX();
y = event.getY();
//
// MAIN MENU
//
if(glb.getChoice()==0)
{
if (cc.ifMenu_exit(x, y))
{
thread.setRunning(false);
((Activity)getContext()).finish();
}
else if (cc.ifMenu_pagsasanay(x,y))
{
thread.menu_pagsasanay();
}
}
//
// PAGSASANAY MENU
//
if(glb.getChoice()==1)
{
Log.d(TAG,"PAGSASANAY MENU");
if (cc.ifPagsasanay_pitik(x, y))
{
pitik = new PitikBulagAnimation(
BitmapFactory.decodeResource(getResources(), R.drawable.hand_sprites)
, 450, 60 // initial position
, 350, 41 // width and height of sprite
, 50, 6); // FPS and number of frames in the animation
Log.d(TAG,"pitik");
thread.pitikAnimation();
}
else if (cc.ifPagsasanay_jnp(x, y))
{
jnp = new JNPAnimation(
BitmapFactory.decodeResource(getResources(), R.drawable.ai_sprite)
, 550, 70 // initial position
, 283, 41 // width and height of sprite
, 50, 4); // FPS and number of frames in the animation
Log.d(TAG,"jnp");
thread.jnpAnimation();
}
if(cc.ifBackButton(x, y))
{
thread.menu_main();
}
err.. glb.getChoice 如果值为零,则表示视图包含主菜单。我的问题是,如果我单击“pagsasanay”按钮(在主菜单内),我可以转到 Pagsasanay 菜单,并且 glb 类中的选项将设置为 1,但到达那里后,event.getX() 值仍然存在,因此单击另一个与“pagsasanay”按钮坐标完全相同的按钮