MapView,MapFrament和SupportMapFragment之间的区别 [英] Differences between MapView, MapFrament and SupportMapFragment
问题描述
我会知道这些差异,因为我正在开发一个应用程序,并且我将介绍Google Map API v2,以便在Android 2.3以上版本中进行编译. 我应该使用哪个?
MapView:
一个显示map
的视图(包含从Google Maps服务获得的数据).聚焦后,它将捕获key-presses
和touch
手势来移动地图.
此类的用户必须将包含该视图的所有生命周期方法从Activity
或Fragment
转发到此类中的相应生命周期方法.
如果要在
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 afragment
. (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
intoActivity
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屋!