- <?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:onClick="setZoomEnable"
- 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:onClick="setScrollEnable"
- 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:onClick="setRotateEnable"
- 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:onClick="setOverlookEnable"
- 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:onClick="setCompassEnable"
- android:text="开启指南针" />
- </LinearLayout>
- <com.baidu.mapapi.map.MapView
- android:id="@+id/bmapView"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:clickable="true" />
- </LinearLayout>
- /**
- * 演示地图UI控制功能
- * 介绍开关手势功能和显示隐藏UI控件
- */
- public class UISettingDemo extends Activity {
- /**
- * MapView 是地图主控件
- */
- private MapView mMapView;
- private BaiduMap mBaiduMap;
- //UiSettings:百度地图 UI 控制器
- private UiSettings mUiSettings;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_uisetting);
- mMapView = (MapView) findViewById(R.id.bmapView);
- mBaiduMap = mMapView.getMap();
- /**
- * getUiSettings():获取地图ui控制器
- * */
- mUiSettings = mBaiduMap.getUiSettings();
- MapStatus ms = new MapStatus.Builder().overlook(-30).build();
- MapStatusUpdate u = MapStatusUpdateFactory.newMapStatus(ms);
- mBaiduMap.animateMapStatus(u, 1000);
- }
- /**
- * 是否启用缩放手势
- *
- * @param v
- */
- public void setZoomEnable(View v) {
- /**
- *setZoomGesturesEnabled(boolean enabled):设置是否允许缩放手势
- * */
- mUiSettings.setZoomGesturesEnabled(((CheckBox) v).isChecked());
- }
- /**
- * 是否启用平移手势
- *
- * @param v
- */
- public void setScrollEnable(View v) {
- /**
- *setScrollGesturesEnabled(boolean enabled):设置是否允许拖拽手势
- * */
- mUiSettings.setScrollGesturesEnabled(((CheckBox) v).isChecked());
- }
- /**
- * 是否启用旋转手势
- *
- * @param v
- */
- public void setRotateEnable(View v) {
- /**
- *setRotateGesturesEnabled(boolean enabled):设置是否允许旋转手势
- * */
- mUiSettings.setRotateGesturesEnabled(((CheckBox) v).isChecked());
- }
- /**
- * 是否启用俯视手势
- *
- * @param v
- */
- public void setOverlookEnable(View v) {
- /**
- *setOverlookingGesturesEnabled(boolean enabled):设置是否允许俯视手势
- * */
- mUiSettings.setOverlookingGesturesEnabled(((CheckBox) v).isChecked());
- }
- /**
- * 是否启用指南针图层
- *
- * @param v
- */
- public void setCompassEnable(View v) {
- /**
- *setCompassEnabled(boolean enabled):设置是否允许指南针
- * */
- mUiSettings.setCompassEnabled(((CheckBox) v).isChecked());
- }
- @Override
- protected void onPause() {
- // MapView的生命周期与Activity同步,当activity挂起时需调用MapView.onPause()
- mMapView.onPause();
- super.onPause();
- }
- @Override
- protected void onResume() {
- // MapView的生命周期与Activity同步,当activity恢复时需调用MapView.onResume()
- mMapView.onResume();
- super.onResume();
- }
- @Override
- protected void onDestroy() {
- // MapView的生命周期与Activity同步,当activity销毁时需调用MapView.destroy()
- mMapView.onDestroy();
- super.onDestroy();
- }
- }