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

别来无恙 提交于 2020-01-11 05:31:06

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8224852/how-to-create-an-irregular-shaped-imagebutton-where-transparent-part-of-image-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!