如何创建不规则形状的图像按钮,其中图像的透明部分不可点击?
我有一个不规则形状的 PNG 图像,例如角是透明的圆形图像。
如何创建该图像的图像按钮并且不让角落可触摸?
如果可能的话,我可能想创建其他不规则形状的图像按钮。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看这个问题的第二个答案,我相信这正是您所需要的。
稍后编辑:
快速摘要:
使用
TouchListener
而不是ClickListener
在监听器内部,如果事件是
MotionEvent.ACTION_DOWN
,则获取触摸坐标检查您之前获得的坐标处的图像像素;如果像素不透明,则认为按钮被单击,否则忽略该事件。
Check out the second answer to this question, I believe it's exactly what you need.
Later edit:
Quick summary:
Use a
TouchListener
instead ofClickListener
Inside the listener, if the event is
MotionEvent.ACTION_DOWN
, get the touch coordinatesCheck 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.