編輯:關於 Android 開發
分類:C#、Android;日期:2016-02-04
自 v2.3.5 起,百度地圖控件支持多實例:開發者可以在同一頁面創建多個地圖對象,分別操作而不互相干擾。本示例在一個界面內並排放置四個 TextureMapView,各自定位到不同城市。
文件名:Demo04MultiMapView.cs
在上一節示例的基礎上,只需再增加以下三步。運行效果如下:
1. 添加 demo05_multimap.axml 布局文件
放在 layout 文件夾下,用兩層 LinearLayout 把四個地圖 Fragment 排成 2×2:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
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>
2. 添加 Demo05MultiMapView.cs
在 SdkDemos 文件夾下新建該文件:
using Android.App;
using Android.Content.PM;
using Android.OS;
using Com.Baidu.Mapapi.Map;
using Com.Baidu.Mapapi.Model;
namespace BdMapV371Demos.SrcSdkDemos
{
/// <summary>
/// 在一個 Activity 中展示多個地圖
/// </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>
/// 初始化各個地圖的中心點
/// </summary>
private void InitMap()
{
TextureMapFragment map1 = FragmentManager
.FindFragmentById<TextureMapFragment>(Resource.Id.map1);
map1.BaiduMap.SetMapStatus(MapStatusUpdateFactory.NewLatLng(Geo_BeiJing));
TextureMapFragment map2 = FragmentManager
.FindFragmentById<TextureMapFragment>(Resource.Id.map2);
map2.BaiduMap.SetMapStatus(MapStatusUpdateFactory.NewLatLng(Geo_ShangHai));
TextureMapFragment map3 = FragmentManager
.FindFragmentById<TextureMapFragment>(Resource.Id.map3);
map3.BaiduMap.SetMapStatus(MapStatusUpdateFactory.NewLatLng(Geo_GuangZhou));
TextureMapFragment map4 = FragmentManager
.FindFragmentById<TextureMapFragment>(Resource.Id.map4);
map4.BaiduMap.SetMapStatus(MapStatusUpdateFactory.NewLatLng(Geo_ShenZhen));
}
}
}
3. 修改 MainActivity.cs
在 demos 字段定義中加入新示例的入口:
// 示例5——多地圖展示
new DemoInfo<Activity>(Resource.String.demo_title_multimap,
Resource.String.demo_desc_multimap, new Demo05MutiMapView()),
運行後即可看到四個地圖分別定位到北京、上海、廣州與深圳。
零停機重啟神器 Huptime 深度剖析
零停機重啟神器 Huptime 深度剖析零停機重啟程序工具 Huptime 研究.pdf目錄導覽本文將依序介紹:官方專案位置、核心功能、環境需求、實作原理,接著深入 SI
Android 對話框實戰:通知、單選、多選與進度框一次搞懂
Android 對話框實戰:通知、單選、多選與進度框一次搞懂 在實際開發中,當應用需要向使用者確認某項操作、展示一段提示資訊,或是回報「正在處理中」的狀態時,對話框(Di
Android 廣播機制 BroadcastReceiver 完整入門
Android 系統內部定義了大量廣播:電池狀態改變、來電、簡訊抵達、開機完成,都會送出對應的廣播訊息。當然,開發者也可以自行定義專屬的廣播。 有廣播就一定有發送者與接收
Android 安全攻防戰(下):反編譯與代碼混淆技術完全解析
Android 安全攻防戰(下):反編譯與代碼混淆技術完全解析 上一篇我們學習了 Android 程序反編譯的知識,包括反編譯代碼、反編譯資源以及重新打包。由此可見,我們