Home  >  Article  >  php教程  >  【Android】第3章(4)MapFragment的使用

【Android】第3章(4)MapFragment的使用

WBOY
WBOYOriginal
2016-07-06 13:30:18845browse

分类:C#、Android、VS2015、百度地图应用; 创建日期:2016-02-04 3.3 示例3--MapFragment的使用 一、简介 TextureMapFragment:用于显示地图片段。 二、示例3--Demo03MapFragment.cs 文件名:Demo02MapFragment.cs 简介:介绍在Fragment框架下使用地图 详

分类:C#、Android、VS2015、百度地图应用; 创建日期:2016-02-04

 

3.3 示例3--MapFragment的使用

一、简介

TextureMapFragment:用于显示地图片段。

二、示例3--Demo03MapFragment.cs

文件名:Demo02MapFragment.cs

简介:介绍在Fragment框架下使用地图

详述:介绍如何在Fragment框架下添加一个TextureMapFragment控件;

1、运行截图

在x86模拟器中运行的效果如下:

2、设计步骤

在上一节例子的基础上,只需要再增加下面的步骤即可。

(1)修改布局文件

将demo02_fragment.xml换名为demo02_fragment.xml,这样做的目的是为了便于观察例子对应的布局文件。

(2)添加Demo03MapFragment.cs

在SrcSdkDemos下添加该文件。

using Android.App;
using Android.OS;
using Android.Content.PM;
using Com.Baidu.Mapapi.Map;

namespace BdMapV371Demos.SrcSdkDemos
{
    [Activity(Label = "@string/demo_name_map_fragment",
        ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden,
         ScreenOrientation = ScreenOrientation.Sensor)]
    public class Demo03MapFragment : Activity
    {
        PRivate TextureMapFragment map;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.demo03_fragment);

            MapStatus ms = new MapStatus.Builder()
                .Target(MainActivity.HeNanUniversity)
                .Overlook(20)
                .Zoom(15)
                .Build();
            BaiduMapOptions bo = new BaiduMapOptions()
                .MapStatus(ms)
                .CompassEnabled(false)
                .ZoomControlsEnabled(true);
            map =TextureMapFragment.NewInstance(bo);
            FragmentManager.BeginTransaction().Add(Resource.Id.map,
                map, "map_fragment").Commit();
        }
    }
}

(3)修改MainActivity.cs

在MainActivity.cs文件的demos字段定义中添加下面的代码。

          //示例3--MapFragment使用
            new DemoInfo(Resource.String.demo_title_map_fragment,
                Resource.String.demo_desc_map_fragment,
                new Demo03MapFragment()),

运行观察结果。


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:NET环境中使用RabbitMQNext article:net实现ping的方法