gpt4 book ai didi

Android MapView 使用 ViewPager 和 PageTransformer 消失

转载 作者:行者123 更新时间:2023-11-30 02:11:54 26 4
gpt4 key购买 nike

我在使用 PageTransformer 和 MapView 设置 ViewPager 时遇到问题。问题是当 viewpager 设置为使用 PageTransformer 时,mapview 在平移时消失(变为透明)。但是,如果我不使用转换器而只是平移 Mapview 就可以了。有谁知道是什么导致了这种行为?

目前 PageTransformer 没有做任何特别的事情,只是设置它似乎会影响 map View 的绘制方式。我应该注意到 map 变得透明,而 map View (法律声明)仍然存在。当 ViewPager 进入空闲状态时, map 出现。

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();
}

最佳答案

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

我将我的 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);

关于Android MapView 使用 ViewPager 和 PageTransformer 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29985454/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com