本文介绍了移动MapFragment(SurfaceView)使黑色背景闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图推行新的Andr​​oid谷歌地图API(V2)。然而,它似乎并没有与 SlidingMenu 顺利。正如你可能知道, MapFragment 的实现是基于 SurfaceView 。问题是, SurfaceView 不喜欢四处移动它 - 我的意思是将其放置在可移动的观点:

I'm trying to implement new Android Google Maps API (v2). However it doesn't seem to go well with SlidingMenu. As you may know, MapFragment implementation is based on SurfaceView. The problem is that the SurfaceView doesn't like moving it around - I mean placing it in movable views:

  • <$c$c>ViewPager,
  • <$c$c>ScrollView,
  • <一个href="http://stackoverflow.com/questions/14218124/new-gms-maps-mapview-rendering-lags-a-bit-when-in-a-listview?lq=1"><$c$c>ListView,
  • 或上述 SlidingMenu
  • ViewPager,
  • ScrollView,
  • ListView,
  • or the aforementioned SlidingMenu.

当您移动它,它留下了黑洞在其像素奠定最初的地方。它看起来像this.

When you move it, it leaves a black hole in the place where its pixels originally layed. It looks something like this.

这个问题可以部分地通过指定一个透明的背景解决了 SurfaceView ,甚至将一个透明的查看过它。我实在不明白,如果只为我的结果是不可接受的,如果我有一个不同的问题,这使它看起来它的外观。

This problem can be partially solved by specifying a transparent background on the SurfaceView or even placing a transparent View over it. I just can't figure if only for me the results are unacceptable, or if I have a different problem which makes it look how it looks.

要看看它的外观,请观看本视频

To see how it looks, please watch THIS VIDEO.

(遗憾的质量,但这个问题可以很容易地看出反正)

(sorry for the quality, but the problem can be seen easily anyway)

在一个正常的列表视图(橙色屏幕)被拉走,同时打开 SlidingMenu ,动画流畅,美观大方。但只要 MapFragment 出现,有一些怪异的令人耳目一新/闪烁/同步问题在地图上。

When a normal listview (the orange screen) is pulled away while opening SlidingMenu, the animation is smooth and nice. But as soon as the MapFragment appears, there's some weird refreshing/flickering/synchronization issue on the map.

在测试的HTC One S和三星Galaxy ACE。

Tested on HTC One S and Samsung Galaxy ACE.

我的超级骗子疯狂解决它的想法:每个开场动画启动时,采取截图的 MapFragment (应该是可能的SurfaceView ),并奠定了它在动画的持续时间。但我真的不知道该怎么做... Taking地图的截图是不可能的,但也许有人会得到这个启发。

Taking screenshot of a map isn't possible, but maybe someone will get inspired by this.

或许禁用重绘地图上一些其他的方式,我不知道。

Or maybe disable redrawing the map some other way, I don't know.

更新:

找到的this.

似乎SurfaceView可以改为TextureView去除这些限制。但由于MapFragment基于SurfaceView,我不知道它是否能够实现。

It appears that SurfaceView can be changed to TextureView to remove those limitations. But since MapFragment is based on SurfaceView, I don't know if it can be achieved.

另一个更新看来,这个问题已经解决了对设备4.1+。他们只是用TextureView。但较低的版本,我们还是要用的解决方法。

Another updateIt appears that this issue has been resolved on devices 4.1+. They just used TextureView. but on lower versions we still have to use workarounds.

推荐答案

当然,正确的解决方案将是谷歌解决这个问题(见Android地图V2问题4639:的)。

Of course the proper solution will be for Google to fix the problem (see Android Maps V2 issue 4639: http://code.google.com/p/gmaps-api-issues/issues/detail?id=4639).

不过,我的一个同事建议简单地扩展超出其容器中的地图。如果我们延长了地图片段超出其容器的可见区域,像这样:

However, one of my coworkers suggested simply extending the map beyond its container. If we extend the map fragment beyond the visible region of its container, like so:

android:layout_marginLeft="-40dp"
android:layout_marginRight="-40dp"

我们可以降低/消除闪烁。较新的设备(如Galaxy Nexus的)显示此黑客后无闪烁,和旧设备(如LG擎天柱V)显示减少闪烁。我们必须扩展利润两侧,所以当他们选定的信息窗口居中。

we can reduce/eliminate the flickering. Newer devices (e.g. Galaxy Nexus) show no flickering after this hack, and older devices (e.g. LG Optimus V) show reduced flickering. We have to extend margins on both sides so that info windows are centered when they're selected.

更新:这个问题是在8月28日固定由谷歌,但我猜它仍然被卷成发布

Update: This issue was fixed by Google on Aug. 28, but I'm guessing it still has to be rolled into a release.

这篇关于移动MapFragment(SurfaceView)使黑色背景闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 09:04