分類:C#、Android、VS201五、百度地圖應用; 建立日期:2016-02-04android
簡介:介紹開關手勢功能和顯示隱藏UI控件api
詳述:app
(1)地圖操做開關:平移、縮放、雙擊放大、雙指操做(旋轉度和俯視度);ide
(2)控件顯示開關:顯示/隱藏縮放按鈕;ui
(3)指南針位置控制:顯示在地圖左上角或者右上角(僅舉例),開發者可據實際狀況任意改變位置;spa
(4)底圖標註開關:控制顯示/隱藏底圖POI,隱藏POI可獲得僅顯示道路信息的地圖設計
運行截圖code
在x86模擬器中的運行效果以下:xml
在上一節例子的基礎上,只須要再增長下面的步驟便可。blog
在layout文件夾下添加該文件,將其改成下面的代碼:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="50dip" android:orientation="horizontal" > <CheckBox android:id="@+id/zoom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:checked="true" android:text="縮放" /> <CheckBox android:id="@+id/scroll" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:checked="true" android:text="平移" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="50dip" android:orientation="horizontal" > <CheckBox android:id="@+id/rotate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:checked="true" android:text="旋轉" /> <CheckBox android:id="@+id/overlook" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:checked="true" android:text="俯視" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="50dip" android:orientation="horizontal" > <CheckBox android:id="@+id/compass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:checked="true" android:text="開啓指南針" /> <CheckBox android:id="@+id/mappoi" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:checked="true" android:text="底圖標註" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="50dip" android:orientation="horizontal" > <CheckBox android:id="@+id/allGesture" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:checked="false" android:text="禁用全部手勢" /> <CheckBox android:id="@+id/setPadding" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:checked="true" android:text="設置Padding" /> </LinearLayout> <com.baidu.mapapi.map.TextureMapView android:id="@+id/bmapView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:clickable="true" /> </LinearLayout>
在SrcSdkDemos文件夾下添加該文件,而後將其內容改成下面的代碼:
using Android.App; using Android.Content.PM; using Android.OS; using Android.Widget; using Com.Baidu.Mapapi.Map; namespace BdMapV371Demos.SrcSdkDemos { /// <summary> /// 演示地圖UI控制功能 /// </summary> [Activity(ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden, Label = "@string/demo_name_ui", ScreenOrientation = ScreenOrientation.Sensor)] public class Demo07UISetting : Activity { private TextureMapView mMapView; protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.demo07_uisetting); mMapView = FindViewById<TextureMapView>(Resource.Id.bmapView); BaiduMap mBaiduMap = mMapView.Map; mBaiduMap.SetMapStatus(MapStatusUpdateFactory.NewLatLng(MainActivity.HeNanUniversity)); UiSettings mUiSettings = mBaiduMap.UiSettings; MapStatus ms = new MapStatus.Builder().Overlook(-30).Build(); MapStatusUpdate u = MapStatusUpdateFactory.NewMapStatus(ms); mBaiduMap.AnimateMapStatus(u, 1000); var zoom= FindViewById<CheckBox>(Resource.Id.zoom); zoom.CheckedChange += (s,e)=> { //是否啓用縮放手勢 mUiSettings.ZoomGesturesEnabled = e.IsChecked; }; var scroll = FindViewById<CheckBox>(Resource.Id.scroll); scroll.CheckedChange += (s, e) => { //是否啓用平移手勢 mUiSettings.ScrollGesturesEnabled = e.IsChecked; }; var rotate = FindViewById<CheckBox>(Resource.Id.rotate); rotate.CheckedChange += (s, e) => { //是否啓用旋轉手勢 mUiSettings.RotateGesturesEnabled = e.IsChecked; }; var overlook = FindViewById<CheckBox>(Resource.Id.overlook); overlook.CheckedChange += (s, e) => { //是否啓用俯視手勢 mUiSettings.OverlookingGesturesEnabled = e.IsChecked; }; var compass = FindViewById<CheckBox>(Resource.Id.compass); compass.CheckedChange += (s, e) => { //是否啓用指南針圖層 mUiSettings.CompassEnabled = e.IsChecked; }; var mappoi = FindViewById<CheckBox>(Resource.Id.mappoi); mappoi.CheckedChange += (s, e) => { //是否顯示底圖默認標註 mBaiduMap.ShowMapPoi(e.IsChecked); }; } protected override void OnPause() { mMapView.OnPause(); base.OnPause(); } protected override void OnResume() { mMapView.OnResume(); base.OnResume(); } protected override void OnDestroy() { mMapView.OnDestroy(); base.OnDestroy(); } } }
三、修改MainActivity.cs文件
在MainActivity.cs文件的demos字段定義中,去掉【示例7】下面的註釋。
運行觀察結果。