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.
Asked
Active
Viewed 1,215 times
7
-
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
-
1With 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 Answers
4
Only for Your understanding.. (By default android View is in Rectangle shape so it apply same for Button)
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.Use
Inset
look at this tutorial http://www.anotherandroidblog.com/2011/07/01/button-hit-area-for-custom-graphics/Implement TouchDelegates look at this tutorial http://www.vogella.com/blog/2012/04/15/android-using-touchdelegates/

user370305
- 108,599
- 23
- 164
- 151