如何创建一个不规则形状的ImageButton,其中图像的透明部分无法点击? [英] How to create an irregular shaped imagebutton where transparent part of image is not clickable?

查看:546
本文介绍了如何创建一个不规则形状的ImageButton,其中图像的透明部分无法点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有例如一个不规则形状的PNG图像圆图像,其中边角都是透明的。

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

我怎样才能创建这个图像的ImageButton的,而不是让角落被触及的?

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

如果可能,我可能要创建其他不规则形状的imagebuttons。

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

推荐答案

退房的第二个答案来这问题,我相信这正是你需要的。

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

后来编辑:

快速总结:


  1. 使用 TouchListener 而不是 ClickListener

在监听,如果该事件是 MotionEvent.ACTION_DOWN ,让触摸坐标

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

查看图像的像素在先前获得的坐标;如果像素是不是透明的,考虑按钮被点击,否则忽略该事件。

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.

这篇关于如何创建一个不规则形状的ImageButton,其中图像的透明部分无法点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆