Android的图形页面覆盖在缩放时消失缩放、图形、页面、Android

2023-09-08 10:24:38 作者:哥、一表人渣

我工作的一个简单的Andr​​oid应用程序的地图上绘制路线。一切都很顺利,但我有一个问题,我的三星Galaxy S2放大的时候。它工作正常,在银河S3的,所以我不知道是否它的内存管理相关的较低specced设备上。它还在模拟器上正常工作。

I'm working on a simple Android app for plotting routes on a map. All is going well, but I have an issue when zooming in on my Samsung Galaxy S2. It works fine on a Galaxy S3, so I'm wondering whether it's related to memory management on the lower specced device. It also works fine on the emulator.

下面相当于code设在覆盖的OnDraw方法,只是浓缩了张贴在这里:

Here is equivalent code located in the overlays onDraw method, just condensed for posting here:

Point current = new Point();
Path path = new Path();
Projection projection = mapView.getProjection();

Iterator<GeoPoint> iterator = pointList.iterator();
if (iterator.hasNext()) {
    projection.toPixels(iterator.next(), current);
    path.moveTo((float) current.x, (float) current.y);
} else return path;
while(iterator.hasNext()) {
    projection.toPixels(iterator.next(), current);
    path.lineTo((float) current.x, (float) current.y);
}

Paint roadPaint = new Paint();
roadPaint.setAntiAlias(true);
roadPaint.setStrokeWidth(8.0f);
roadPaint.setColor(Color.BLACK);
roadPaint.setStyle(Paint.Style.STROKE);

canvas.drawPath(path, roadPaint);

这不是太不相似的大部分样品code左右浮动这样做。我只是想知道如果任何人都可以证实我的怀疑,并建议如果有什么我可以配置或调整方面做了我能做的强制在所有缩放级别绘制?

It's not too dissimilar to most of the sample code floating around for doing this. I'm just wondering if anyone can confirm my suspicions and advise if there is anything I can do in terms of configuration or tweaks that I can do to force drawing at all zoom levels?

在此先感谢。

干杯, 内森

推荐答案

您说,code以上是等效的(不是真正的code,你正在运行),并是十分明显的,因为你是返回一个路径的对象的OnDraw()。

You said that code above was an equivalent (not the real code you are running) and that's clear because you are returning a Path object in a onDraw() which you couldn't.

您展示应该工作的COM pressed表code,以及使用的drawLine()。所以,这个问题应该从其他的东西(也许原来的code)。

The "compressed form" of code you show should work as well as using the drawLine(). So the problem should come from something else (may the original code).

不管怎样,我给你一对夫妇的提示:

Anyway, I'll give you a couple of hints:

当物体的顶部和底部您绘制到帆布都出画面,对象将被忽略,并且不绘制。检查这是不是发生了什么与你的路。请参阅我的答案在这个岗位Android地图覆盖消失在放大 您不必每次都重建路径对象。你可能已经在做了,这就是为什么你做上面的短版。请参阅我的答案在这篇文章中有一些建议,以改善路径图:Overlay行为变焦时

如果由于某种原因,你真的想用的drawLine较慢的方法(),您可以使用follwing,使该行更好看: When the top and bottom of object you are drawing to a canvas are both out of screen, the object is ignored and not drawn. Check if this is not whats happening with your path. See my answer in this post Android Map Overlay Disappears on Zoom You don't need to rebuild the path object every time. You are probably already doing it, and that's why you made the short version above. See my answer in this post with some suggestions to improve path drawing: Overlay behavior when zooming

If for some reason you really want to use the slower approach of drawLine(), you can use the follwing to make the line look better:

paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setColor(...);
paint.setAlpha(...);
paint.setStrokeWidth(...);

最后,如果问题仍然存在,与更多的相关code更新你的问题,让我知道。也许我可以进一步帮助。

Finally, if the issue remains, update your question with more relevant code and let me know. Maybe I can help further.

问候。