Android intermediate-level Baidu map SDK v3.5.0-FragmentMap framework [graphic SupportMapFragment class] And androidsdk installation Diagram
Create a Fragment-Based Map Framework
- SupportMapFragment
SupportMapFragmentClass to manage the map lifecycle.
- Constructor Overview
Constructor and description:
SupportMapFragment()
Constructor
- Method Overview
Qualifier and type |
Method |
Description |
BaiduMap |
GetBaiduMap () |
Obtain the Baidu map controller. It is called after the onCreateView function is executed. Otherwise, null is returned. |
MapView |
GetMapView () |
Get Baidu map control |
Static SupportMapFragment |
NewInstance () |
Create a MapFragment instance |
Static SupportMapFragment |
NewInstance (BaiduMapOptions options) |
Create a SupportMapFragment instance based on the given Baidu map Option |
Void |
OnActivityCreated (Bundle savedInstanceState) |
* |
Void |
OnAttach (Activity activity) |
* |
Void |
OnConfigurationChanged (Configuration newConfig) |
It is called when the configuration is changed |
Void |
OnCreate (Bundle savedInstanceState) |
* |
View |
OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) |
* |
Void |
OnDestroy () |
* |
Void |
OnDestroyView () |
* |
Void |
OnDetach () |
* |
Void |
OnPause () |
* |
Void |
OnResume () |
* |
Void |
OnSaveInstanceState (Bundle outState) |
* |
Void |
OnStart () |
* |
Void |
OnStop () |
* |
Void |
OnViewCreated (View view, Bundle savedInstanceState) |
* |
Void |
OnViewStateRestored (Bundle savedInstanceState) |
* |
- Use of MapFragment
Createactivity_fragment.xml
:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <FrameLayout android:id="@+id/fm_map" android:layout_width="match_parent" android:layout_height="match_parent"></FrameLayout></LinearLayout>
CreateMapFragmentDemo
Class inheritanceBaseActivity:
Public class MapFragmentDemo extends BaseActivity {private suppmapmapfragment map; private FragmentManager fm; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_fragment); // overlook: zoom down; zoom: zoom MapStatus MS = new MapStatus. builder (). overlook (-20 ). zoom (15 ). build (); // whether compassEnabled enables the compass; zoomControlsEnabled: whether to scale proportionally; BaiduMapOptions bo = new BaiduMapOptions (). mapStatus (MS ). compassEnabled (false ). zoomControlsEnabled (false); map = SupportMapFragment. newInstance (bo); fm = getSupportFragmentManager (); fm. beginTransaction (). add (R. id. fm_map, map, "map_fragemnt "). commit ();}}
Run:
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.