Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an irregular shaped imagebutton where transparent part of image is not clickable?

I have an irregular shaped PNG image for example a round image where the corners are transparent.

How can I create an imagebutton of this image and not letting the corners being touchable?

If possible I may want to create other irregular shaped imagebuttons.

like image 256
Wuahaha Avatar asked Nov 22 '11 09:11

Wuahaha


1 Answers

Check out the second answer to this question, I believe it's exactly what you need.

Later edit:

Quick summary:

  1. Use a TouchListener instead of ClickListener

  2. Inside the listener, if the event is MotionEvent.ACTION_DOWN, get the touch coordinates

  3. Check the image's pixel at the coordinates you obtained earlier; if the pixel is not transparent, consider the button was clicked, otherwise ignore the event.

like image 115
Gabriel Negut Avatar answered Sep 21 '22 07:09

Gabriel Negut