简体   繁体   English

具有多个可点击区域/表面/区域的图像

[英]Image that has multi clickable zones/surface/area

I want to have an image on the android screen where different parts of the image can be clickable. 我想在android屏幕上显示图像,在该图像中可以单击图像的不同部分。 What I mean is that, If its an image of 3 circles, I want to be able to click each of these circles, 我的意思是,如果该图像包含3个圆圈,则我希望能够单击每个圆圈,

Then I can add different functionalities to each of these clickable circles. 然后,我可以为每个可点击的圈子添加不同的功能。 For an instance in this image below I want to be able to click each distinct color. 对于下面这张图中的实例,我希望能够单击每种不同的颜色。 Is it possible to have on-touch-listener and get you the color ? 是否可以使用触摸式监听器并获得颜色? and can it be an image or has to be drawn in Java OR XML ? 可以是图像还是必须用Java或XML绘制?

在此处输入图片说明

I found a really good widget that helps you make any image muli-clickable. 我找到了一个非常好的窗口小部件,可以帮助您使任何图像都可点击。 They have some good notes on how to use their widget as well. 他们还对如何使用其小部件有一些很好的说明。

The widget has a similar approach as Image mapping in html. 该小部件具有与html中的图像映射类似的方法。 The good thing about this widget is that the image can be zoomed and it will not lose the coordinates or areas associated to specific clicks. 关于此小部件的好处是,图像可以缩放,并且不会丢失与特定点击相关的坐标或区域。

Here is the link to their website. 这是他们网站的链接。 the guy who made the widget apparently had similar problem and came up with this widget. 制作该小部件的人显然也遇到了类似的问题,并提出了这个小部件。

Another solution would have been 另一个解决方案是

  • creating an ImageView containing the png file referenced 创建一个包含引用的png文件的ImageView
  • making the whole ImageView clickable 使整个ImageView可点击
  • setting an OnTouchListener to the ImageView which overrides the onTouch method 将OnTouchListener设置为ImageView,它会覆盖onTouch方法
  • check the colors of the image pixel at the touch position 检查触摸位置的图像像素的颜色

This is often done with an invisible mask image with one color for each zone (see the popular detailed tutorial ), but here the image itself has distinct colors for each zone which makes it more interesting. 这通常是用不可见的蒙版图像完成的,每个区域都有一种颜色(请参见流行的详细教程 ),但是此处图像本身的每个区域都有不同的颜色,这使其变得更加有趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM