Android地圖控件之多地圖展示
一、簡(jiǎn)介
地圖控件自v2.3.5版本起,支持多實(shí)例,即開(kāi)發(fā)者可以在一個(gè)頁(yè)面中建立多個(gè)地圖對(duì)象,并且針對(duì)這些對(duì)象分別操作且不會(huì)產(chǎn)生相互干擾。
文件名:Demo04MultiMapView.cs
簡(jiǎn)介:介紹多MapView的使用
詳述:在一個(gè)界面內(nèi),同時(shí)建立四個(gè)TextureMapView控件;
二、示例
1、運(yùn)行截圖
在x86模擬器中的運(yùn)行效果如下:
在上一節(jié)例子的基礎(chǔ)上,只需要再增加下面的步驟即可。
2、添加demo05_multimap.axml文件
在layout文件夾下添加該文件,將其改為下面的代碼:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginBottom="5dp" android:layout_weight="1" android:orientation="horizontal" > <fragment android:id="@+id/map1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginRight="5dp" android:layout_weight="1" class="com.baidu.mapapi.map.TextureMapFragment" /> <fragment android:id="@+id/map2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" class="com.baidu.mapapi.map.TextureMapFragment" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal" > <fragment android:id="@+id/map3" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginRight="5dp" android:layout_weight="1" class="com.baidu.mapapi.map.TextureMapFragment" /> <fragment android:id="@+id/map4" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" class="com.baidu.mapapi.map.TextureMapFragment" /> </LinearLayout> </LinearLayout>
3、添加Demo05MultiMapView.cs文件
在SdkDemos文件夾下添加該文件,然后將其內(nèi)容改為下面的代碼:
using Android.App; using Android.Content.PM; using Android.OS; using Com.Baidu.Mapapi.Map; using Com.Baidu.Mapapi.Model; namespace BdMapV371Demos.SrcSdkDemos { /// <summary> /// 在一個(gè)Activity中展示多個(gè)地圖 /// </summary> [Activity(Label = "@string/demo_name_multimap", ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden, ScreenOrientation = ScreenOrientation.Sensor)] public class Demo05MutiMapView : Activity { private readonly LatLng Geo_BeiJing = new LatLng(39.945, 116.404); private readonly LatLng Geo_ShangHai = new LatLng(31.227, 121.481); private readonly LatLng Geo_GuangZhou = new LatLng(23.155, 113.264); private readonly LatLng Geo_ShenZhen = new LatLng(22.560, 114.064); protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.demo05_multimap); InitMap(); } /// <summary> /// 初始化Map /// </summary> private void InitMap() { MapStatusUpdate u1 = MapStatusUpdateFactory.NewLatLng(Geo_BeiJing); TextureMapFragment map1 = FragmentManager.FindFragmentById<TextureMapFragment>(Resource.Id.map1); map1.BaiduMap.SetMapStatus(u1); MapStatusUpdate u2 = MapStatusUpdateFactory.NewLatLng(Geo_ShangHai); TextureMapFragment map2 = FragmentManager.FindFragmentById<TextureMapFragment>(Resource.Id.map2); map2.BaiduMap.SetMapStatus(u2); MapStatusUpdate u3 = MapStatusUpdateFactory.NewLatLng(Geo_GuangZhou); TextureMapFragment map3 = FragmentManager.FindFragmentById<TextureMapFragment>(Resource.Id.map3); map3.BaiduMap.SetMapStatus(u3); MapStatusUpdate u4 = MapStatusUpdateFactory.NewLatLng(Geo_ShenZhen); TextureMapFragment map4 = FragmentManager.FindFragmentById<TextureMapFragment>(Resource.Id.map4); map4.BaiduMap.SetMapStatus(u4); } } }
4、修改MainActivity.cs文件
在MainActivity.cs文件的demos字段定義中添加下面的代碼。
//示例5--多地圖展示 new DemoInfo<Activity>(Resource.String.demo_title_multimap, Resource.String.demo_desc_multimap, new Demo05MutiMapView()),
運(yùn)行觀察結(jié)果。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
簡(jiǎn)單掌握Android Widget桌面小部件的創(chuàng)建步驟
這篇文章主要介紹了簡(jiǎn)單掌握Android Widget桌面小部件的創(chuàng)建步驟,Widget一般采用web前端技術(shù)進(jìn)行開(kāi)發(fā),需要的朋友可以參考下2016-03-03Android Studio實(shí)現(xiàn)幀動(dòng)畫(huà)
這篇文章主要為大家詳細(xì)介紹了Android Studio實(shí)現(xiàn)幀動(dòng)畫(huà),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11Android實(shí)現(xiàn)炫酷的網(wǎng)絡(luò)直播彈幕功能
這篇文章主要為大家詳細(xì)介紹了Android仿網(wǎng)絡(luò)直播彈幕功能的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11Android retrofit上傳文件實(shí)例(包含頭像)
下面小編就為大家分享一篇Android retrofit上傳文件實(shí)例(包含頭像),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-01-01Android 解決嵌套Fragment無(wú)法接收onCreateOptionsMenu事件的問(wèn)題
本文主要介紹Android Fragment無(wú)法接收onCreateOptionsMenu事件的問(wèn)題,這里給出解決辦法以及詳細(xì)代碼,希望能幫助有需要的小伙伴2016-07-07Android View添加 Listener 實(shí)例代碼
在開(kāi)發(fā)中為控件添加Listener是非常常見(jiàn)的工作,最簡(jiǎn)單的添加Listener方式可以這樣2013-05-05Flutter使用?input?chip?標(biāo)簽組件示例詳解
這篇文章主要為大家介紹了Flutter使用?input?chip?標(biāo)簽組件示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10Android UI實(shí)現(xiàn)多行文本折疊展開(kāi)效果
這篇文章主要為大家詳細(xì)介紹了Android UI實(shí)現(xiàn)多行文本折疊展開(kāi)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10