How to confine touch/swipe to a particular area on smartphone's screen ?

I need to be able to confine touch and swipes to particular areas on the screen. For example a button would only be in one place on my Android screen and I want to allow touch to be working only around that area and not somewhere else. Same goes for an area where user needs to perform a swipe.

How do I do that?