android ImageView超链接坐标

发布于 2024-12-06 18:57:05 字数 613 浏览 0 评论 0原文

我想实现一个功能,当 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 技术交流群。

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

发布评论

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

评论(1

宛菡 2024-12-13 18:57:05

另一种可能的方法是为自己创建一个使用透明 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.

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