BaiduMap---百度地图官方Demo之UI控制功能(介绍开关手势功能和显示隐藏UI控件)

本文介绍如何使用百度地图SDK实现地图UI控制和手势功能开关,包括缩放、平移、旋转及俯视等手势操作,同时展示了如何通过代码控制指南针图层的显示与隐藏。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[html]  view plain  copy
 print ?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <LinearLayout  
  8.         android:layout_width="fill_parent"  
  9.         android:layout_height="50dip"  
  10.         android:orientation="horizontal" >  
  11.   
  12.         <CheckBox  
  13.             android:id="@+id/zoom"  
  14.             android:layout_width="wrap_content"  
  15.             android:layout_height="wrap_content"  
  16.             android:layout_weight="1"  
  17.             android:checked="true"  
  18.             android:onClick="setZoomEnable"  
  19.             android:text="缩放" />  
  20.   
  21.         <CheckBox  
  22.             android:id="@+id/scroll"  
  23.             android:layout_width="wrap_content"  
  24.             android:layout_height="wrap_content"  
  25.             android:layout_weight="1"  
  26.             android:checked="true"  
  27.             android:onClick="setScrollEnable"  
  28.             android:text="平移" />  
  29.     </LinearLayout>  
  30.   
  31.     <LinearLayout  
  32.         android:layout_width="fill_parent"  
  33.         android:layout_height="50dip"  
  34.         android:orientation="horizontal" >  
  35.   
  36.         <CheckBox  
  37.             android:id="@+id/rotate"  
  38.             android:layout_width="wrap_content"  
  39.             android:layout_height="wrap_content"  
  40.             android:layout_weight="1"  
  41.             android:checked="true"  
  42.             android:onClick="setRotateEnable"  
  43.             android:text="旋转" />  
  44.   
  45.         <CheckBox  
  46.             android:id="@+id/overlook"  
  47.             android:layout_width="wrap_content"  
  48.             android:layout_height="wrap_content"  
  49.             android:layout_weight="1"  
  50.             android:checked="true"  
  51.             android:onClick="setOverlookEnable"  
  52.             android:text="俯视" />  
  53.     </LinearLayout>  
  54.   
  55.     <LinearLayout  
  56.         android:layout_width="fill_parent"  
  57.         android:layout_height="50dip"  
  58.         android:orientation="horizontal" >  
  59.   
  60.         <CheckBox  
  61.             android:id="@+id/compass"  
  62.             android:layout_width="wrap_content"  
  63.             android:layout_height="wrap_content"  
  64.             android:layout_weight="1"  
  65.             android:checked="true"  
  66.             android:onClick="setCompassEnable"  
  67.             android:text="开启指南针" />  
  68.     </LinearLayout>  
  69.   
  70.     <com.baidu.mapapi.map.MapView  
  71.         android:id="@+id/bmapView"  
  72.         android:layout_width="fill_parent"  
  73.         android:layout_height="wrap_content"  
  74.         android:clickable="true" />  
  75.   
  76. </LinearLayout>  




[java]  view plain  copy
 print ?
  1. /** 
  2.  * 演示地图UI控制功能 
  3.  * 介绍开关手势功能和显示隐藏UI控件 
  4.  */  
  5. public class UISettingDemo extends Activity {  
  6.   
  7.     /** 
  8.      * MapView 是地图主控件 
  9.      */  
  10.     private MapView mMapView;  
  11.     private BaiduMap mBaiduMap;  
  12.     //UiSettings:百度地图 UI 控制器  
  13.     private UiSettings mUiSettings;  
  14.   
  15.     @Override  
  16.     public void onCreate(Bundle savedInstanceState) {  
  17.         super.onCreate(savedInstanceState);  
  18.         setContentView(R.layout.activity_uisetting);  
  19.   
  20.         mMapView = (MapView) findViewById(R.id.bmapView);  
  21.         mBaiduMap = mMapView.getMap();  
  22.         /** 
  23.          * getUiSettings():获取地图ui控制器 
  24.          * */       
  25.         mUiSettings = mBaiduMap.getUiSettings();  
  26.   
  27.         MapStatus ms = new MapStatus.Builder().overlook(-30).build();  
  28.         MapStatusUpdate u = MapStatusUpdateFactory.newMapStatus(ms);  
  29.         mBaiduMap.animateMapStatus(u, 1000);  
  30.     }  
  31.   
  32.     /** 
  33.      * 是否启用缩放手势 
  34.      * 
  35.      * @param v 
  36.      */  
  37.     public void setZoomEnable(View v) {  
  38.         /** 
  39.          *setZoomGesturesEnabled(boolean enabled):设置是否允许缩放手势 
  40.          * */  
  41.         mUiSettings.setZoomGesturesEnabled(((CheckBox) v).isChecked());  
  42.     }  
  43.   
  44.     /** 
  45.      * 是否启用平移手势 
  46.      * 
  47.      * @param v 
  48.      */  
  49.     public void setScrollEnable(View v) {  
  50.         /** 
  51.          *setScrollGesturesEnabled(boolean enabled):设置是否允许拖拽手势 
  52.          * */  
  53.         mUiSettings.setScrollGesturesEnabled(((CheckBox) v).isChecked());  
  54.     }  
  55.   
  56.     /** 
  57.      * 是否启用旋转手势 
  58.      * 
  59.      * @param v 
  60.      */  
  61.     public void setRotateEnable(View v) {  
  62.         /** 
  63.          *setRotateGesturesEnabled(boolean enabled):设置是否允许旋转手势 
  64.          * */  
  65.         mUiSettings.setRotateGesturesEnabled(((CheckBox) v).isChecked());  
  66.     }  
  67.   
  68.     /** 
  69.      * 是否启用俯视手势 
  70.      * 
  71.      * @param v 
  72.      */  
  73.     public void setOverlookEnable(View v) {  
  74.         /** 
  75.          *setOverlookingGesturesEnabled(boolean enabled):设置是否允许俯视手势 
  76.          * */  
  77.         mUiSettings.setOverlookingGesturesEnabled(((CheckBox) v).isChecked());  
  78.     }  
  79.   
  80.     /** 
  81.      * 是否启用指南针图层 
  82.      * 
  83.      * @param v 
  84.      */  
  85.     public void setCompassEnable(View v) {  
  86.         /** 
  87.          *setCompassEnabled(boolean enabled):设置是否允许指南针 
  88.          * */  
  89.         mUiSettings.setCompassEnabled(((CheckBox) v).isChecked());  
  90.     }  
  91.   
  92.     @Override  
  93.     protected void onPause() {  
  94.         // MapView的生命周期与Activity同步,当activity挂起时需调用MapView.onPause()  
  95.         mMapView.onPause();  
  96.         super.onPause();  
  97.     }  
  98.   
  99.     @Override  
  100.     protected void onResume() {  
  101.         // MapView的生命周期与Activity同步,当activity恢复时需调用MapView.onResume()  
  102.         mMapView.onResume();  
  103.         super.onResume();  
  104.     }  
  105.   
  106.     @Override  
  107.     protected void onDestroy() {  
  108.         // MapView的生命周期与Activity同步,当activity销毁时需调用MapView.destroy()  
  109.         mMapView.onDestroy();  
  110.         super.onDestroy();  
  111.     }  
  112.   
  113. }  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值