1

I'm trying to find a way how to set clickable regions on oval button. As you can see on the image attached below, Android put the images/backgrounds of buttons in square and if I want an oval button and click on the square where the background is transparent I'm still pressing the blue button, not the green one. I need to be able to set that square as oval maybe..or even some other shape so I can use onClickListener only when I press the image.

I hope I explain it correctly! Anyone who has an idea how to achieve this?

enter image description here

Android-Droid
  • 14,365
  • 41
  • 114
  • 185
  • Use RelativeLayout to put a transparent circle shape above the area you want to click on, and handle the events from this shape. – superM May 03 '12 at 10:19
  • Yeah, but I still have that square which i want to remove so I can click only on oval image. – Android-Droid May 03 '12 at 10:40
  • Why don't you remove the button at all? If you are using the circle shape for click event, than you don't need the button. – superM May 03 '12 at 10:52
  • Actually I need the image to be there. I've tried to set it as background of relative layout, but it's the same situation. – Android-Droid May 03 '12 at 10:59
  • Set your image in an ImageView and "cover" it with a transparent shape. Than set listener for the shape. – superM May 03 '12 at 11:00
  • I would recommend this method: [Make a clickable map image with each country producing a different action](http://stackoverflow.com/a/4942812/2455518). – MosabJ Apr 17 '16 at 02:09

3 Answers3

1

I would do it the following way: create own view; in the onTouch check if the coordinates are in the region you want and if so call the onClickListener

ligi
  • 39,001
  • 44
  • 144
  • 244
1

I think u need to put android:background="@null" in your ImageView tag... Or crop that image to oval shape then put it Resource..

Pradeep
  • 2,530
  • 26
  • 37
0

I think if the background of your oval button is transparent.

It can achieve.

Changwei Yao
  • 13,051
  • 3
  • 25
  • 22