我使用SupportMapFragment在ScrollView中显示静态 Map . 我不喜欢移动/缩放 Map ,只显示位置 .
当我向下/向上滚动时, Map 在其边界内摇晃,感觉非常迟钝 . 我的问题是,如何才能消除这种滞后,或者如何使用静态版本的v2 api映射 .
这是我的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/margin_half"
android:background="@color/white"
android:orientation="vertical" >
...
<fragment
android:id="@+id/fragmentMap"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_alignParentLeft="true"
android:layout_below="@id/viewDivider"
android:layout_margin="@dimen/margin_half"
/>
<View
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_alignBottom="@id/fragmentMap"
android:layout_alignLeft="@id/fragmentMap"
android:layout_alignRight="@id/fragmentMap"
android:layout_alignTop="@id/fragmentMap"
android:background="@android:color/transparent" />
...
</RelativeLayout>
这与MapFragment in ScrollView并不真正相关,即使我使用此技巧来删除旧设备上的黑色剪辑,正如您可以看到的透明视图 .
我还禁用了所有手势和 Map 视图的点击功能:
getMap().getUiSettings().setAllGesturesEnabled(false);
getMap().getUiSettings().setZoomControlsEnabled(false);
getMap().getUiSettings().setMyLocationButtonEnabled(false);
...
mapView.setClickable(false);
mapView.setFocusable(false);
mapView.setDuplicateParentStateEnabled(false);
2 回答
随着新版Google Play服务的推出,Google添加了一个snapshot方法,以便检索当前显示的 Map 的位图,而该 Map 可能会显示 . 所以互动是不可能的,但在租用时, Map 不再动摇 .
使用
并实现SnapshotReadyCallback . 传送快照后,将MapFragment替换为包含快照的ImageView .
这个例子在onResume方法中运行得很好:
Sidenote: 要使用新版本,请运行Android SDK Manager的更新,并在使用maven时运行maven-android-sdk-deployer:
尝试使用这个类,至少在我们的scrollview中向右和向左滚动它应该看起来更好: