android ImageView超链接坐标
我想实现一个功能,当 ImageView 中设置的图像的特定区域将导致调用意图。
与 HTML 坐标超链接类似,
<img src ="planets.gif" width="145" height="126" alt="Planets" usemap ="#planetmap" />
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun" />
<area shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury" />
<area shape="circle" coords="124,58,8" href="venus.htm" alt="Venus" />
</map>
我什至想在缩放图像中实现此功能。
这是我搜索并找到的线索:
我必须在 onTouch() 中使用具有适当逻辑的 SurfaceView;
mapViews 获取投影方法也有类似的功能。与此类似,但应该是加载的位图。
I want to implement a functionality in which when particular area of an image set in an ImageView will result in calling an intent.
Similar to HTML coords hyperlinks
<img src ="planets.gif" width="145" height="126" alt="Planets" usemap ="#planetmap" />
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun" />
<area shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury" />
<area shape="circle" coords="124,58,8" href="venus.htm" alt="Venus" />
</map>
I want to implement this even in an zoomed image.
Heres what I have search and found leads on:
I will have to use an SurfaceView with appropriate logic in onTouch();
Similar functionality is there on mapViews get projection method. similar to that but should be to a bitmap loaded.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
另一种可能的方法是为自己创建一个使用透明 9 色块作为背景的视图。将其设置为您需要的任何大小和位置,并从其 onClickListener() 调用您的意图。从用户的角度来看,这也达到了同样的效果。
编辑:
如果您想要同时多个活动,则必须使用多个透明视图。如果您一次只想激活 1 个活动,则可以重复使用同一个活动,只需更改其大小/位置即可。
由于使用这种方法会创建额外的视图,因此您的性能将会受到轻微影响。如果您希望最大限度地提高性能,请执行上面提到的操作,即附加 OnTouchListener 并将逻辑放在 onTouch 回调中。您可以创建 Rect 对象来表示触摸区域,并调用 Rect.intersect() 来查看触摸事件位置是否与您的矩形区域之一相交。这可能会给您带来更好的整体性能。
Another possible approach is create yourself a view that uses a transparent 9 patch as its background. Set it to whatever size and position you need and call your intent from its onClickListener(). This is achieve the same effect from the users perspective.
Edit:
If you want multiple active at the same time you'd have to use multiple transparent views. If you only want 1 active at a time you could reuse the same one and just change the size / position of it.
Since using this approach will create extra views you are going to take a slight performance hit. If you are looking to maximize preformance doing something like you've mentioned above where you attach an OnTouchListener and have your logic inside the onTouch callback. You could creat Rect objects to represent your touch areas and call Rect.intersect() to see if the touch event position intersects one of your rect areas. This would likely give you better overall performance.