MapView,MapFrament和SupportMapFragment之间的区别 [英] Differences between MapView, MapFrament and SupportMapFragment

查看:251
本文介绍了MapView,MapFrament和SupportMapFragment之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会知道这些差异,因为我正在开发一个应用程序,并且我将介绍Google Map API v2,以便在Android 2.3以上版本中进行编译. 我应该使用哪个?

解决方案

MapView:

一个显示map的视图(包含从Google Maps服务获得的数据).聚焦后,它将捕获key-pressestouch手势来移动地图.

此类的用户必须将包含该视图的所有生命周期方法从ActivityFragment转发到此类中的相应生命周期方法.

如果要在fragment中添加map,请使用它. (你需要 将每个生命周期更新为MapView.

请参阅Google API 文档

MapFragment:

应用程序中的Map组件. fragment是在应用程序中放置map的最简单方法.它是围绕地图视图的包装器,可自动处理必要的生命周期需求.

如果要将map添加到Activity类(而不是片段)中,请使用它 因为它会创建一个嵌套的片段,而且一团糟).

请参阅Google API 文档.

SupportMapFragment:

应用程序中的Map组件. fragment是在应用程序中放置地图的最简单方法.它是围绕map视图的包装程序,可自动处理必要的生命周期需求.作为fragment,该组件可以简单地添加到activity's布局文件中

如果您定位的Android API级别低于12,请使用SupportMapFragment.

请参阅Google API 文档.

I would know the differences because I'm developing an app and I would introduce Google Map API v2 for compiling above Android 2.3. Which should I use?

解决方案

MapView:

A View which displays a map (with data obtained from the Google Maps service). When focused, it will capture key-presses and touch gestures to move the map.

Users of this class must forward all the life cycle methods from the Activity or Fragment containing this view to the corresponding ones in this class.

Use it if you are going to add a map into a fragment. (you need to update each lifecycle to MapView).

See Google API Documentation

MapFragment:

A Map component in an app. This fragment is the simplest way to place a map in an application. It's a wrapper around a view of a map to automatically handle the necessary life cycle needs.

Use it if you want to add a map into Activity class (not fragment because it will create a nested fragment and it´s a mess).

See Google API Documentation.

SupportMapFragment:

A Map component in an app. This fragment is the simplest way to place a map in an application. It's a wrapper around a view of a map to automatically handle the necessary life cycle needs. Being a fragment, this component can be added to an activity's layout file simply

Use SupportMapFragment if you are targeting Android API levels below 12.

See Google API Documentation.

这篇关于MapView,MapFrament和SupportMapFragment之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆