Create a fragment-based map frame
- Supportmapfragment
supportmapfragment class to manage the map life cycle.
- Constructor overview
Constructors and descriptions:
SupportMapFragment()
constructor function
- Overview of methods
Qualifiers and Types |
Method |
Description |
Baidumap |
Getbaidumap () |
Gets the Baidu map controller, called after executing the Oncreateview function, otherwise returns NULL. |
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 sends changes |
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
Create activity_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"> <framelayoutandroid:id="@+id/fm_map"android:layout_width= "Match_parent" android:layout_height="Match_parent"> </framelayout></linearlayout>
To MapFragmentDemo
Create a class inheritance baseactivity :
Public class mapfragmentdemo extends baseactivity { PrivateSupportmapfragment map;PrivateFragmentmanager FM;@Override protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (r.layout.activity_fragment);//overlook: Overlooking angle; zoom: ZoomMapstatus ms =NewMapstatus.builder (). Overlook (- -). Zoom ( the). build ();//compassenabled whether to turn on the compass; zoomcontrolsenabled: whether proportional scaling;Baidumapoptions bo =NewBaidumapoptions (). 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 NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android intermediate Baidu Map SDK V3.5.0-fragmentmap map Frame [graphic supportmapfragment class]