首页 > 系统 > Android > 正文

【Android】第3章(8)UI控制功能

2019-11-14 13:28:22
字体:
来源:转载
供稿:网友

分类:C#、Android、VS2015、百度地图应用; 创建日期:2016-02-04

一、简介

简介:介绍开关手势功能和显示隐藏UI控件

详述:

(1)地图操作开关:平移、缩放、双击放大、双指操作(旋转度和俯视度);

(2)控件显示开关:显示/隐藏缩放按钮;

(3)指南针位置控制:显示在地图左上角或者右上角(仅举例),开发者可据实际情况任意改变位置;

(4)底图标注开关:控制显示/隐藏底图POI,隐藏POI可得到仅显示道路信息的地图

运行截图

在x86模拟器中的运行效果如下:

image

二、设计步骤

在上一节例子的基础上,只需要再增加下面的步骤即可。

1、添加demo07_uisetting.axml文件

在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>

 

2、添加Demo07UISetting.cs文件

在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();        }    }}

3、修改MainActivity.cs文件

在MainActivity.cs文件的demos字段定义中,去掉【示例7】下面的注释。

运行观察结果。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表