0

I am using triangle shape button (PNG image), I need to make clickable only on the image visible area. As you can see in the image of my triangle shape button below , in the image I need to make clickable only on the image visible portion ie black and red, the green area will remain transparent and non clickable. Please help me this respect I would very thankful to you. Thanks in advance.

enter image description here

user1703737
  • 533
  • 1
  • 11
  • 25
  • You will have to restrict the user to only touch the area visible and you will have to do it manually for every button and every different screen size. Not a very good idea. Why do you want to do this?? – the-ginger-geek Mar 20 '13 at 11:23
  • I think you haven’t read my question’s description thoroughly; it’s a button not a plane area and button could be of any shape. More by doing so I’m restricting the button not the user. – user1703737 Mar 20 '13 at 11:41
  • Dear why are you devoting the question, what's wrong in it, please let me know – user1703737 Mar 20 '13 at 11:48
  • Please, if some of the answers helped you mark it as correct so this question doesnt show up as unanswered.... – Marko Niciforovic Mar 20 '13 at 12:46

3 Answers3

1

Identifying image area clicked in Android? check this question

OR if green will be transparent, I think the easiest way to detect whether 'visible' content of the image was clicked, is to hook up an OnTouchListener, get the touch coordinates and subsequently get the color for those coordinates using Bitmap.getPixel(int x, int y). Since this will return an ARBG color, you should have little problems with images using an alpha channel. Anything that is 'transparent' (if green will be transparent?) will be invalid, everything else will mean the actual content was tapped.

something like this as a start up:

int color = Bitmap.getPixel(x,y); // x and y are the location of the touch event in Bitmap space
int alpha = Color.getAlpha(color);
boolean isTransparent = (alpha==0);
Community
  • 1
  • 1
Marko Niciforovic
  • 3,561
  • 2
  • 21
  • 28
0

You can refer to this link:

Image Map

Or you can also refer this similar question :

Link

But, i would not recommend doing so as you have to manually calculate the coordinates and apart from that android screen has different sizes so it may cause a problem for you.

Community
  • 1
  • 1
Sanober Malik
  • 2,765
  • 23
  • 30
0

You can set OnTouchListener to your View and check was click inside of triangle shape or not (OnTouch event sends MotionEvent object, you can get coordinates of touch event from it).

May be it will be better, if button will be clickable as rectangle? Like here, on stackoverflow, vote buttons has triangle form too, but they are clickable on rectangle shape.

Artem Zinnatullin
  • 4,305
  • 1
  • 29
  • 43