7

Can anyone tell me how to avoid presses outside the circle of a round button since "wrap_content" doesn't seem to work. I used an image file to create the button. I appreciate any help. Thanks.

  • maybe the linked answers may help you: (1) http://stackoverflow.com/questions/10266595/how-to-make-a-round-button (2) http://stackoverflow.com/questions/9049868/round-button-in-android-avoid-presses-outside-the-button – rosco Nov 19 '12 at 10:13
  • 1
    With a default `Button` you can't as the view will be a rectangle/square. If you create your own `Button` class then you could determine if the user touched the `Button` outside the circle and ignore that event. There are some questions regarding the exact situation, search stackoverflow. – user Nov 19 '12 at 10:15

1 Answers1

4

Only for Your understanding.. (By default android View is in Rectangle shape so it apply same for Button)

  1. Set Touch Listener to your button and in onTouch() map X-Y co-ordinates for Circle area. If it lies in inside area do what you want else return false.

  2. Use Inset look at this tutorial http://www.anotherandroidblog.com/2011/07/01/button-hit-area-for-custom-graphics/

  3. Implement TouchDelegates look at this tutorial http://www.vogella.com/blog/2012/04/15/android-using-touchdelegates/

user370305
  • 108,599
  • 23
  • 164
  • 151