我正在我的片段中加载 Mapbox,该片段将在从 DrawerLayout 单击时启动。
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.map_fragment, container, false);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
bindUI(getView()); mapView = view.findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(map -> {
mapboxMap = map;
setUpMap();
});
}
@Override
public void onStart() {
super.onStart();
mapView.onStart();
}
@Override
public void onStop() {
super.onStop();
mapView.onStop();
}
@Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
public void onDestroyView() {
super.onDestroyView();
mapView.onDestroy();
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
Run Code Online (Sandbox Code Playgroud)
这是我用于在片段中使用 Mapbox 加载地图的代码。每当我从 Drawer Layout 更改片段时,黑屏闪烁,然后加载地图。
如果我正在加载一些其他片段而不是 Map 片段,它完全可以正常工作。
提前致谢
小智 -1
您可以在 Mapbox 地图上放置一个带有“地图正在加载...”的 TextView 并在 onMapReady 后隐藏它,例如:
@Override
public void onMapReady(MapboxMap mapboxMap) {
mapLoadingOverview.postDelayed(new Runnable() {
public void run() {
mapLoadingOverview.setVisibility(View.GONE);
}
}, 1000);
}
Run Code Online (Sandbox Code Playgroud)
XML
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapboxMapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:mapbox_cameraTargetLat="53.873900"
mapbox:mapbox_cameraTargetLng="10.683876"
mapbox:mapbox_cameraZoom="15"
mapbox:mapbox_styleUrl="@string/mapbox_style_light" />
<TextView
android:id="@+id/mapLoadingOverview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/subwhite"
android:text="@string/mapOverlayText"
android:gravity="center"
android:textColor="@color/maincolor"
android:textSize="@dimen/mapOverlayTextSize"
android:visibility="visible" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1275 次 |
| 最近记录: |