如何创建不规则形状的图像按钮,其中图像的透明部分不可点击?

发布于 2024-12-17 09:53:32 字数 103 浏览 6 评论 0原文

我有一个不规则形状的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墟烟 2024-12-24 09:53:32

查看这个问题的第二个答案,我相信这正是您所需要的。

稍后编辑:

快速摘要:

  1. 使用 TouchListener 而不是 ClickListener

  2. 在监听器内部,如果事件是 MotionEvent.ACTION_DOWN,则获取触摸坐标

  3. 检查您之前获得的坐标处的图像像素;如果像素不透明,则认为按钮被单击,否则忽略该事件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文