我正在开发一款用于触摸和打字手机的应用程序。现在在应用程序的一个屏幕中,有 3 个按钮。
在这里,如果我触摸三个按钮,它正在工作。但是,如果我触摸按钮外部,即在顶部栏中或底部栏中,则触摸事件也正在工作。假设在下面,添加更多按钮是焦点。因此,如果我在底部栏中触摸,则按钮触摸也起作用。为了解决这个问题,我写了下面的代码:
protected boolean touchEvent(TouchEvent event) {
try {
int touchXPos = event.getX(1);
int touchYPos = event.getY(1);
int addBtnXPos = btnAddMore.getLeft();
int saveBtnXPos = btnSave.getLeft();
int helpBtnXpos = btnHelp.getLeft();
int vfmTitleTouch = m_vfmTitle.getHeight();
if(event.getEvent() == TouchEvent.CLICK)
{
if ((touchXPos >= addBtnXPos + 40) && (touchXPos <= (addBtnXPos + btnAddMore.getWidth() + 40)) && (touchYPos <= screenHeight -10) && (touchYPos >= (screenHeight -10 - btnAddMore.getHeight())) /*&& (touchYPos < (screenHeight-gmYPos)) */) {
Logger.out("touchEvent", "------------------------------1");
showPopUp();
} else if ((touchXPos >= saveBtnXPos + 40) && (touchXPos <= (saveBtnXPos + 40 + btnSave.getWidth())) && (touchYPos <= screenHeight -10) && (touchYPos >= (screenHeight -10 - btnSave.getHeight())) /* && (touchYPos < (screenHeight-gmYPos))*/) {
Logger.out("touchEvent", "------------------------------2");
saveToDb();
} else if ((touchXPos >= helpBtnXpos) && (touchXPos <= (helpBtnXpos + btnHelp.getWidth())) && (touchYPos <= (btnHelp.getTop() + btnHelp.getHeight())) && (touchYPos >= btnHelp.getTop()) /* && (touchYPos < (screenHeight-gmYPos))*/ ) {
Logger.out("touchEvent", "------------------------------3");
UiApplication.getUiApplication().pushScreen(new HelpScreen());
} else if ((touchYPos <= screenHeight - hfmBtn.getHeight()) && (touchYPos >= (vfmTitleTouch))) {
Logger.out("touchEvent", "------------------------------4");
//Logger.out("touchEvent", "touchY::::" +touchYPos + "Vfm Title::::" +vfmTitleTouch + " "+"GM Y Pos"+ gmYPos);
}
return true;
}
} catch (Exception e) {
}
return super.touchEvent(event);
}
但它不起作用..任何人都可以帮助我吗?触摸事件应该像复选框一样在屏幕中间工作。
谢谢..