Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to avoid presses outside the circle of a round button using wrap content?

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.

like image 203
user1835374 Avatar asked Nov 19 '12 10:11

user1835374


1 Answers

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/

like image 118
user370305 Avatar answered Oct 17 '22 21:10

user370305