1

I'm working on a project where there is need of a tap gesture on a certain part of the screen to move on to the next screen.

Is there a way that I could set the specific xy coordinates of where the tap will only work? As at the moment the user can tap anywhere on the screen and the screen changes. In other words I want to set a specific area where the tap will only work. Thanks in advance.

progdoc
  • 589
  • 3
  • 11
  • 24

2 Answers2

1

register the layout for a touch listener and get the x and y coordinates using event.getX() and event.getY() where event is a MouseEvent object. Then you will get an idea about which area to tap and when the user does tap within the specified area go to the next screen. Check this link for ontouchlistener example. Implementing OnTouchListener on LinearLayout - Android Development

Community
  • 1
  • 1
Jeris
  • 2,355
  • 4
  • 26
  • 38
1

You can use a GestureDetector and onSingleTapUp(MotionEvent e) to detect the tap event. Then you can use e.getX() and e.getY() to get the event position.

This response explains how to use the GestureDetector. The advantage of using this over the onTouch event is that you don't have to detect if it was really just a tap event or sliding or some other gesture instead.

Community
  • 1
  • 1
Maria Neumayer
  • 3,337
  • 3
  • 27
  • 44