I googled a lot but could not find anything useful. I have a complex png image and I want to make it touchable but for its opaque area only. I set a touch listener for it but it dispatched even I clicked on a transparent area, thats what I DON'T want.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
As @Cata says, a touch event will be associated with the whole of the image. However, the touch event will tell you where in the image the touch was, and so can code something like this (ignoring checking for correct action etc):
The key here is then imageIsOpaque, which you will need to implement, in one of three ways:
The image may be easy to segment into areas of opaque and non opaque in which case:
The image may not be easy to handle that way, in which case you will need to use the x and y touch position to check in the source image (scaled to the size it's on the screen) whether the point is opaque or not. EDIT: You seem to have used this solution in a rather neat way in your comment to @vinod below, so I would recommend to other readers to check that comment out as well.
Even more complex, it may be an image that you are contructing on the fly and never really know it's final state in a searchable way. If this is the case, you will need to build up a separate 2D array of booleans as you create the image determining which points are opaque and which aren't.
Touch listener applies for the entire view and not to a portion of the view.. so I would recommend you to split your image into small pieces and add touch listener on each piece that is opaque.. I hope that can help you, to get more help you can also try to post the image here so we can see better what you want to achieve..
@user1716538: Why dont u use png image? U can remove the unwanted part of the image using png image and hence the click event will not occur on those part of the image.