Category: C#, Android, VS2015, Baidu map application; Creation date: 2016-02-04 3.3 Example 3--Use of MapFragment 1. Introduction TextureMapFragment: used to display map fragments. 2. Example 3--Demo03MapFragment.cs File name: Demo02MapFragment.cs Introduction: Introducing the use of maps under the Fragment framework Details
1. Introduction
TextureMapFragment: used to display map fragments.
File name: Demo02MapFragment.cs
Introduction: Introducing the use of maps under the Fragment framework
Details: Introduce how to add a TextureMapFragment control under the Fragment framework;
1. Running screenshots
The effect of running in x86 simulator is as follows:
2. Design steps
Based on the example in the previous section, you only need to add the following steps.
Rename demo02_fragment.xml to demo02_fragment.xml. The purpose of this is to facilitate the observation of the layout file corresponding to the example.
Add this file under SrcSdkDemos.
<span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.App; </span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.OS; </span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.Content.PM; </span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Com.Baidu.Mapapi.Map; </span><span style="color: #0000ff;">namespace</span><span style="color: #000000;"> BdMapV371Demos.SrcSdkDemos { [Activity(Label </span>= <span style="color: #800000;">"</span><span style="color: #800000;">@string/demo_name_map_fragment</span><span style="color: #800000;">"</span><span style="color: #000000;">, ConfigurationChanges </span>= ConfigChanges.Orientation |<span style="color: #000000;"> ConfigChanges.KeyboardHidden, ScreenOrientation </span>=<span style="color: #000000;"> ScreenOrientation.Sensor)] </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> Demo03MapFragment : Activity { </span><span style="color: #0000ff;">PRivate</span><span style="color: #000000;"> TextureMapFragment map; </span><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnCreate(Bundle savedInstanceState) { </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnCreate(savedInstanceState); SetContentView(Resource.Layout.demo03_fragment); MapStatus ms </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> MapStatus.Builder() .Target(MainActivity.HeNanUniversity) .Overlook(</span><span style="color: #800080;">20</span><span style="color: #000000;">) .Zoom(</span><span style="color: #800080;">15</span><span style="color: #000000;">) .Build(); BaiduMapOptions bo </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> BaiduMapOptions() .MapStatus(ms) .CompassEnabled(</span><span style="color: #0000ff;">false</span><span style="color: #000000;">) .ZoomControlsEnabled(</span><span style="color: #0000ff;">true</span><span style="color: #000000;">); map </span>=<span style="color: #000000;">TextureMapFragment.NewInstance(bo); FragmentManager.BeginTransaction().Add(Resource.Id.map, map, </span><span style="color: #800000;">"</span><span style="color: #800000;">map_fragment</span><span style="color: #800000;">"</span><span style="color: #000000;">).Commit(); } } }</span>
Add the following code in the demos field definition of the MainActivity.cs file.
<span style="color: #008000;"> //</span><span style="color: #008000;">示例3--MapFragment使用</span> <span style="color: #0000ff;">new</span> DemoInfo<Activity><span style="color: #000000;">(Resource.String.demo_title_map_fragment, Resource.String.demo_desc_map_fragment, </span><span style="color: #0000ff;">new</span> Demo03MapFragment()),
Run and observe the results.