Android应用程序结构问题

发布于 2024-10-08 07:27:42 字数 1011 浏览 7 评论 0原文

我目前正在开发一个使用 MapView 并向其添加叠加层的应用程序。基本上,在任何给定时间,覆盖列表都不应超过两个。

这就是我尝试做的...

我扩展了 ItemizedOverlay 类 (MyFriendOverlay),然后在该扩展类中创建了一个私有 ArrayList 对象,我将把叠加层附加到该对象上。然而;我遇到了一个问题,我不确定如何解决。如果你看一下这段代码:

ImageView mapMarker = new ImageView(getApplicationContext()); mapMarker.setImageResource(R.drawable.markertrp);

myPointsToShow = new myFriendOverlay(mapMarker.getDrawable(), getApplicationContext());

如此处所示,我创建了一个带有基于我的绘图的图标。之后,我从 ItemizedOverlay 获得了扩展课程。在构造函数中,它需要两个参数:可绘制对象和上下文。

据我所知,下面的构造函数是必需的(也许可以修改):

公共 myFriendOverlay(Drawable defaultMarker,Context 上下文) 这里的问题

是我不断创建 myPointsToShow 的新实例,这是一个问题,因为我有一个想要在扩展类中使用的 ArrayList,这样我就可以直接控制覆盖层。通过每次实例化一个新的,我并没有真正添加到列表本身。

简而言之:

我想要的只是我的应用程序有两个点(A 和 B),如果检测到 B 的新位置,则从覆盖列表中删除 B,并将其替换为新地点。 A 也一样。为了简化它,我想将索引 0 附加到 A,将索引 1 附加到 B,这样它就不会跨越两个点。

由于必要的构造函数的问题,我无法为此提出解决方案,也许我想得太仔细了......

请提供任何反馈! :)

感谢您的阅读。

I am currently working on an application that makes use of a MapView and adds overlays to it. Basically at anyone one given time the overlay list should never exceed two.

Heres what I have tried to do...

I have extended the ItemizedOverlay class (MyFriendOverlay) and then created a private ArrayList object inside that extended class that I would attach the overlays to. However; I have come across a problem that I am unsure how to fix. If you look at this segment of code:


ImageView mapMarker = new ImageView(getApplicationContext());
mapMarker.setImageResource(R.drawable.markertrp);

myPointsToShow = new myFriendOverlay(mapMarker.getDrawable(), getApplicationContext());

As can be noted here I am created a ImageView with an icon based on my drawables. After this I have my extended class from ItemizedOverlay. In the constructor it takes two parameter the drawable and the context.

From what I know the constructor below is required (perhaps it can be modified):


public myFriendOverlay(Drawable defaultMarker, Context context)

Problem here is that I keep creating a new instance of myPointsToShow, which is a problem because I have a ArrayList that I want to use in the extended class so I have direct control over the overlays. And by instantiating a new one every time, I don't really add to the list itself.

In short:

All I want is for my application to have two points (A and B) where if a new location is detected for say B, then remove B from the overlay list, and replace it with the new location. And the same for A as well. In order to simplify it, I want to attach index 0 to A and index 1 to B, so that it doesn't span over two points.

I am unable to come up with a solution for this because of the problem of the necessary constructor, perhaps I'm thinking too hard about it...

Please offer any feedback! :)

Thanks for reading.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

暖风昔人 2024-10-15 07:27:42

根据我的经验,我所做的如下:

  • 为我要显示的每种图像类型创建一个项目叠加层。
  • 如果每个覆盖层的项目列表不是很长,我会将其传递到意图中。

顺便说一句,您需要使用 R.drawable.something 作为叠加层。您不需要创建ImageView

我一直在使用这个 android-library 来制作地图:android-mapviewballoons。一探究竟!

From my experience what I do is the following:

  • Create an item overlay per type of image I am going to show.
  • If the list of items per overlay is not very long I pass it inside an intent.

Btw you need to use R.drawable.something for your overlay. You don't need to create an ImageView.

I have been using this android-library for maps: android-mapviewballoons. Check it out!

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