1

I'm having trouble setting up a ViewPager using a PageTransformer and a MapView. The problem is when the viewpager is set to use the PageTransformer, the mapview disappears(goes transparent) while panning. However, if I don't use a transformer and just pan the Mapview is fine. Does anyone know what is causing this behavior?

Currently the PageTransformer does nothing special but just setting it seems to affect the way the mapview is drawn. I should note that the map goes transparent while the mapview(Legal Notice)remains. When the ViewPager enters an Idle state the Map appears.

viewPager.setPageTransformer(true, this);
...
@Override
public void transformPage(View view, float position) {
}

XML: ViewPager Fragment

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF">
        <com.google.android.gms.maps.MapView
                    android:id="@+id/mapcontainer"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:clickable="false"/>
</FrameLayout>

Map Fragment:

private GoogleMap map;
private MapView mapView;
private Bundle mapBundle;

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    mapBundle = savedInstanceState;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.mapfragment, container, false);
    MapsInitializer.initialize(getActivity());
    mapView = (MapView) rootView.findViewById(R.id.mapcontainer);
    mapView.onCreate(mapBundle);

    map = mapView.getMap();

    return rootView;
}
@Override
public void onResume(){
     super.onResume();
     mapView.onResume();
}

@Override
public void onPause(){
     super.onPause();
     mapView.onPause();
}

@Override
public void onDestroy(){
     super.onDestroy();
     mapView.onDestroy();
}
4

1 回答 1

1

我从讨论线程Bug: Black rectangle background on scroll中找到了一个解决方案,它为我指明了正确的方向。Google Play 服务中似乎有一些错误可以通过将地图设置为“精简模式”来解决。就我而言,它成功了,地图现在在 pagetransformer 中工作。据我了解,精简模式将地图更改为位图图像。您可以在此处阅读有关它的更多信息Google Maps - Lite Mode。Lite 模式有一些限制,例如无法平移或缩放,但在我的情况下,这不是必需的。

我将我的 XML 更新为:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
    <com.google.android.gms.maps.MapView
                xmlns:map="http://schemas.android.com/apk/res-auto"
                android:id="@+id/mapcontainer"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clickable="false"
                map:liteMode="true"/>
</FrameLayout>

您还可以在代码中设置此选项:

GoogleMapOptions options = new GoogleMapOptions().liteMode(true);
MapView mapView = MapView (context, options);
于 2015-05-14T07:35:07.530 回答