首页 >php教程 >php手册 >【Android】第3章(8)UI控制功能

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

WBOY
WBOY原创
2016-07-06 13:30:221025浏览

分类:C#、Android、VS2015、百度地图应用; 创建日期:2016-02-04 一、简介 简介:介绍开关手势功能和显示隐藏UI控件 详述: (1)地图操作开关:平移、缩放、双击放大、双指操作(旋转度和俯视度); (2)控件显示开关:显示/隐藏缩放按钮; (3)指南针

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

一、简介

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

详述:

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

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

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

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

运行截图

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

image

二、设计步骤

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

1、添加demo07_uisetting.axml文件

在layout文件夹下添加该文件,将其改为下面的代码:

<span style="color: #0000ff;"></span><span style="color: #ff00ff;">xml version="1.0" encoding="utf-8"</span><span style="color: #0000ff;">?></span>
<span style="color: #0000ff;"><span style="color: #800000;">LinearLayout </span><span style="color: #ff0000;">xmlns:android</span><span style="color: #0000ff;">="http://schemas.android.com/apk/res/android"</span><span style="color: #ff0000;">
    android:layout_width</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
    android:layout_height</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
    android:orientation</span><span style="color: #0000ff;">="vertical"</span> <span style="color: #0000ff;">></span>

    <span style="color: #0000ff;"><span style="color: #800000;">LinearLayout
        </span><span style="color: #ff0000;">android:layout_width</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
        android:layout_height</span><span style="color: #0000ff;">="50dip"</span><span style="color: #ff0000;">
        android:orientation</span><span style="color: #0000ff;">="horizontal"</span> <span style="color: #0000ff;">></span>

        <span style="color: #0000ff;"><span style="color: #800000;">CheckBox
            </span><span style="color: #ff0000;">android:id</span><span style="color: #0000ff;">="@+id/zoom"</span><span style="color: #ff0000;">
            android:layout_width</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
            android:layout_height</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
            android:layout_weight</span><span style="color: #0000ff;">="1"</span><span style="color: #ff0000;">
            android:checked</span><span style="color: #0000ff;">="true"</span><span style="color: #ff0000;">
            android:text</span><span style="color: #0000ff;">="缩放"</span> <span style="color: #0000ff;">/></span>

        <span style="color: #0000ff;"><span style="color: #800000;">CheckBox
            </span><span style="color: #ff0000;">android:id</span><span style="color: #0000ff;">="@+id/scroll"</span><span style="color: #ff0000;">
            android:layout_width</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
            android:layout_height</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
            android:layout_weight</span><span style="color: #0000ff;">="1"</span><span style="color: #ff0000;">
            android:checked</span><span style="color: #0000ff;">="true"</span><span style="color: #ff0000;">
            android:text</span><span style="color: #0000ff;">="平移"</span> <span style="color: #0000ff;">/></span>
    <span style="color: #0000ff;"></span><span style="color: #800000;">LinearLayout</span><span style="color: #0000ff;">></span>

    <span style="color: #0000ff;"><span style="color: #800000;">LinearLayout
        </span><span style="color: #ff0000;">android:layout_width</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
        android:layout_height</span><span style="color: #0000ff;">="50dip"</span><span style="color: #ff0000;">
        android:orientation</span><span style="color: #0000ff;">="horizontal"</span> <span style="color: #0000ff;">></span>

        <span style="color: #0000ff;"><span style="color: #800000;">CheckBox
            </span><span style="color: #ff0000;">android:id</span><span style="color: #0000ff;">="@+id/rotate"</span><span style="color: #ff0000;">
            android:layout_width</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
            android:layout_height</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
            android:layout_weight</span><span style="color: #0000ff;">="1"</span><span style="color: #ff0000;">
            android:checked</span><span style="color: #0000ff;">="true"</span><span style="color: #ff0000;">
            android:text</span><span style="color: #0000ff;">="旋转"</span> <span style="color: #0000ff;">/></span>

        <span style="color: #0000ff;"><span style="color: #800000;">CheckBox
            </span><span style="color: #ff0000;">android:id</span><span style="color: #0000ff;">="@+id/overlook"</span><span style="color: #ff0000;">
            android:layout_width</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
            android:layout_height</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
            android:layout_weight</span><span style="color: #0000ff;">="1"</span><span style="color: #ff0000;">
            android:checked</span><span style="color: #0000ff;">="true"</span><span style="color: #ff0000;">
            android:text</span><span style="color: #0000ff;">="俯视"</span> <span style="color: #0000ff;">/></span>
    <span style="color: #0000ff;"></span><span style="color: #800000;">LinearLayout</span><span style="color: #0000ff;">></span>

    <span style="color: #0000ff;"><span style="color: #800000;">LinearLayout
        </span><span style="color: #ff0000;">android:layout_width</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
        android:layout_height</span><span style="color: #0000ff;">="50dip"</span><span style="color: #ff0000;">
        android:orientation</span><span style="color: #0000ff;">="horizontal"</span> <span style="color: #0000ff;">></span>

        <span style="color: #0000ff;"><span style="color: #800000;">CheckBox
            </span><span style="color: #ff0000;">android:id</span><span style="color: #0000ff;">="@+id/compass"</span><span style="color: #ff0000;">
            android:layout_width</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
            android:layout_height</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
            android:layout_weight</span><span style="color: #0000ff;">="1"</span><span style="color: #ff0000;">
            android:checked</span><span style="color: #0000ff;">="true"</span><span style="color: #ff0000;">
            android:text</span><span style="color: #0000ff;">="开启指南针"</span> <span style="color: #0000ff;">/></span>

        <span style="color: #0000ff;"><span style="color: #800000;">CheckBox
            </span><span style="color: #ff0000;">android:id</span><span style="color: #0000ff;">="@+id/mappoi"</span><span style="color: #ff0000;">
            android:layout_width</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
            android:layout_height</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
            android:layout_weight</span><span style="color: #0000ff;">="1"</span><span style="color: #ff0000;">
            android:checked</span><span style="color: #0000ff;">="true"</span><span style="color: #ff0000;">
            android:text</span><span style="color: #0000ff;">="底图标注"</span> <span style="color: #0000ff;">/></span>

    <span style="color: #0000ff;"></span><span style="color: #800000;">LinearLayout</span><span style="color: #0000ff;">></span>

    <span style="color: #0000ff;"><span style="color: #800000;">LinearLayout
        </span><span style="color: #ff0000;">android:layout_width</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
        android:layout_height</span><span style="color: #0000ff;">="50dip"</span><span style="color: #ff0000;">
        android:orientation</span><span style="color: #0000ff;">="horizontal"</span> <span style="color: #0000ff;">></span>

        <span style="color: #0000ff;"><span style="color: #800000;">CheckBox
            </span><span style="color: #ff0000;">android:id</span><span style="color: #0000ff;">="@+id/allGesture"</span><span style="color: #ff0000;">
            android:layout_width</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
            android:layout_height</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
            android:layout_weight</span><span style="color: #0000ff;">="1"</span><span style="color: #ff0000;">
            android:checked</span><span style="color: #0000ff;">="false"</span><span style="color: #ff0000;">
            android:text</span><span style="color: #0000ff;">="禁用所有手势"</span> <span style="color: #0000ff;">/></span>

        <span style="color: #0000ff;"><span style="color: #800000;">CheckBox
            </span><span style="color: #ff0000;">android:id</span><span style="color: #0000ff;">="@+id/setPadding"</span><span style="color: #ff0000;">
            android:layout_width</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
            android:layout_height</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
            android:layout_weight</span><span style="color: #0000ff;">="1"</span><span style="color: #ff0000;">
            android:checked</span><span style="color: #0000ff;">="true"</span><span style="color: #ff0000;">
            android:text</span><span style="color: #0000ff;">="设置Padding"</span> <span style="color: #0000ff;">/></span>

    <span style="color: #0000ff;"></span><span style="color: #800000;">LinearLayout</span><span style="color: #0000ff;">></span>

    <span style="color: #0000ff;"><span style="color: #800000;">com.baidu.mapapi.map.TextureMapView
        </span><span style="color: #ff0000;">android:id</span><span style="color: #0000ff;">="@+id/bmapView"</span><span style="color: #ff0000;">
        android:layout_width</span><span style="color: #0000ff;">="fill_parent"</span><span style="color: #ff0000;">
        android:layout_height</span><span style="color: #0000ff;">="wrap_content"</span><span style="color: #ff0000;">
        android:clickable</span><span style="color: #0000ff;">="true"</span> <span style="color: #0000ff;">/></span>

<span style="color: #0000ff;"></span><span style="color: #800000;">LinearLayout</span><span style="color: #0000ff;">></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>

 

2、添加Demo07UISetting.cs文件

在SrcSdkDemos文件夹下添加该文件,然后将其内容改为下面的代码:

<span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.App;
</span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.Content.PM;
</span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.OS;
</span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Android.Widget;
</span><span style="color: #0000ff;">using</span><span style="color: #000000;"> Com.Baidu.Mapapi.Map;

</span><span style="color: #0000ff;">namespace</span><span style="color: #000000;"> BdMapV371Demos.SrcSdkDemos
{
    </span><span style="color: #808080;">///</span> <span style="color: #808080;"><summary></summary></span>
    <span style="color: #808080;">///</span><span style="color: #008000;"> 演示地图UI控制功能
    </span><span style="color: #808080;">///</span> <span style="color: #808080;"></span>
    [Activity(ConfigurationChanges = ConfigChanges.Orientation |<span style="color: #000000;"> ConfigChanges.KeyboardHidden,
        Label </span>= <span style="color: #800000;">"</span><span style="color: #800000;">@string/demo_name_ui</span><span style="color: #800000;">"</span><span style="color: #000000;">, 
        ScreenOrientation </span>=<span style="color: #000000;"> ScreenOrientation.Sensor)]
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> Demo07UISetting : Activity
    {
        </span><span style="color: #0000ff;">PRivate</span><span style="color: #000000;"> TextureMapView mMapView;

        </span><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnCreate(Bundle savedInstanceState)
        {
            </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.demo07_uisetting);

            mMapView </span>= FindViewById<texturemapview><span style="color: #000000;">(Resource.Id.bmapView);
            BaiduMap mBaiduMap </span>=<span style="color: #000000;"> mMapView.Map;
            mBaiduMap.SetMapStatus(MapStatusUpdateFactory.NewLatLng(MainActivity.HeNanUniversity));

            UiSettings mUiSettings </span>=<span style="color: #000000;"> mBaiduMap.UiSettings;

            MapStatus ms </span>= <span style="color: #0000ff;">new</span> MapStatus.Builder().Overlook(-<span style="color: #800080;">30</span><span style="color: #000000;">).Build();
            MapStatusUpdate u </span>=<span style="color: #000000;"> MapStatusUpdateFactory.NewMapStatus(ms);
            mBaiduMap.AnimateMapStatus(u, </span><span style="color: #800080;">1000</span><span style="color: #000000;">);
            
            </span><span style="color: #0000ff;">var</span> zoom= FindViewById<checkbox><span style="color: #000000;">(Resource.Id.zoom);
            zoom.CheckedChange </span>+= (s,e)=><span style="color: #000000;">
            {
                </span><span style="color: #008000;">//</span><span style="color: #008000;">是否启用缩放手势</span>
                mUiSettings.ZoomGesturesEnabled =<span style="color: #000000;"> e.IsChecked;
            };

            </span><span style="color: #0000ff;">var</span> scroll = FindViewById<checkbox><span style="color: #000000;">(Resource.Id.scroll);
            scroll.CheckedChange </span>+= (s, e) =><span style="color: #000000;">
            {
                </span><span style="color: #008000;">//</span><span style="color: #008000;">是否启用平移手势</span>
                mUiSettings.ScrollGesturesEnabled =<span style="color: #000000;"> e.IsChecked;
            };

            </span><span style="color: #0000ff;">var</span> rotate = FindViewById<checkbox><span style="color: #000000;">(Resource.Id.rotate);
            rotate.CheckedChange </span>+= (s, e) =><span style="color: #000000;">
            {
                </span><span style="color: #008000;">//</span><span style="color: #008000;">是否启用旋转手势</span>
                mUiSettings.RotateGesturesEnabled =<span style="color: #000000;"> e.IsChecked;
            };

            </span><span style="color: #0000ff;">var</span> overlook = FindViewById<checkbox><span style="color: #000000;">(Resource.Id.overlook);
            overlook.CheckedChange </span>+= (s, e) =><span style="color: #000000;">
            {
                </span><span style="color: #008000;">//</span><span style="color: #008000;">是否启用俯视手势</span>
                mUiSettings.OverlookingGesturesEnabled =<span style="color: #000000;"> e.IsChecked;
            };

            </span><span style="color: #0000ff;">var</span> compass = FindViewById<checkbox><span style="color: #000000;">(Resource.Id.compass);
            compass.CheckedChange </span>+= (s, e) =><span style="color: #000000;">
            {
                </span><span style="color: #008000;">//</span><span style="color: #008000;">是否启用指南针图层</span>
                mUiSettings.CompassEnabled =<span style="color: #000000;"> e.IsChecked;
            };

            </span><span style="color: #0000ff;">var</span> mappoi = FindViewById<checkbox><span style="color: #000000;">(Resource.Id.mappoi);
            mappoi.CheckedChange </span>+= (s, e) =><span style="color: #000000;">
            {
                </span><span style="color: #008000;">//</span><span style="color: #008000;">是否显示底图默认标注</span>
<span style="color: #000000;">                mBaiduMap.ShowMapPoi(e.IsChecked);
            };

        }

        </span><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnPause()
        {
            mMapView.OnPause();
            </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnPause();
        }

        </span><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnResume()
        {
            mMapView.OnResume();
            </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnResume();
        }

        </span><span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> OnDestroy()
        {
            mMapView.OnDestroy();
            </span><span style="color: #0000ff;">base</span><span style="color: #000000;">.OnDestroy();
        }
    }
}</span></checkbox></checkbox></checkbox></checkbox></checkbox></checkbox></texturemapview>

3、修改MainActivity.cs文件

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

运行观察结果。


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn