Search code examples
androidandroid-canvasontouchlistener

Android touchlistener at specific canvas


would like to get some helps from fellows. I am creating a custom analog clock which consists of clock dial, hour hand, minute hand, second hand and alarm hand. The user can rotate the alarm hand to set the alarm. I would like to let user to touch only the alarm hand but not other place to set the alarm. However, current on touch listener method I am using will be detecting touch on the whole canvas which including the clock dial, hour hand and etc. How can I detect user touch at the alarm hand and do the job?


Solution

  • Canvas is not a layout so the view your drawn on the canvas will not be a normal view anymore. It is no possible to listen the touch event just on the alarm part.All you can do is to calculate whether the pointer you touch down(or up) is just on the alarm hand.