安卓谷歌地图V2片段黑屏问题

6
如何在滚动时使 Google 地图 V2 中的黑色背景透明?
<RelativeLayout
                    android:id="@+id/relativeLayout1"
                    android:layout_width="match_parent"
                    android:layout_height="134dp"
                    android:layout_alignParentTop="true"
                    android:layout_gravity="center" >

                    <fragment
                        xmlns:android="http://schemas.android.com/apk/res/android"
                        android:id="@+id/map"
                        android:layout_width="fill_parent"
                        android:layout_height="434dp"
                        android:layout_marginBottom="-150dp"
                        android:layout_marginLeft="3dp"
                        android:layout_marginRight="3dp"
                        android:layout_marginTop="-150dp"                       
                        class="com.google.android.gms.maps.SupportMapFragment"
                        android:cacheColorHint="@color/transparent"
                        android:clickable="true" />

                    <FrameLayout
                        android:id="@+id/fram_lay"
                        android:layout_width="match_parent"
                        android:layout_height="172dp" >

                        <android.support.v4.view.ViewPager
                            android:id="@+id/fragment_container"
                            android:layout_width="fill_parent"
                            android:layout_height="134dp" >
                        </android.support.v4.view.ViewPager>

                        <FrameLayout
                            android:id="@+id/fram_lay2"
                            android:layout_width="match_parent"
                            android:layout_height="334dp"
                            android:layout_marginTop="-100dp"                            
                            android:background="@android:color/transparent"
                            android:cacheColorHint="#00000000" />
                    </FrameLayout>
                </RelativeLayout>

我在地图上添加了透明的框架,但是它仍然在闪烁。 请有经验的人提供解决方案。 谢谢。

2个回答

1
透明的框架覆盖在MapView上只会解决黑洞问题,每次地图重新加载资源时,即调用OnCreateView()时仍会出现闪烁问题。尝试在主Activity中添加一个MapView,然后在初始化后隐藏它,可以参考此处发布的解决方案。

0

这背后的原因是 Map 使用了 SurfaceView,当应用程序创建此视图时,它会在您的 Activity 后面创建一个窗口并打个洞,意味着您的 Activity 窗口下方的东西无法看到 SurfaceView 的原始位置。

对我来说,这非常有用,您可以使用这个库。

https://github.com/NyxDigital/NiceSupportMapFragment/

这对我来说很好用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接