Change zoom controls in a MapView

2020-06-21 03:23发布

问题:

I would like to change the predefined style of the zoom controls in my application to appear like the new zoom controls in the google maps application. See below:

How can I do it? I have been looking around and I haven't found anything.

Thanks in advance.

回答1:

You should have four image drawables namely:

  1. Zoom in (+) enable/disable
  2. Zoom out (-) enable/disable

Put them in MapView layout an ImageView or Button with background image as the above drawables.

Then you should assign onClickListeners like:

zoomIn.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        mapView.getController.zoomIn()
        checkzoom();
    }
});

zoomOut.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        mapView.getController.zoomOut()
        checkzoom();
    }
});

public void checkzoom() {
    if(mapView.getZoomLevel()==1) // dont know if 0 or 1, just wrote it
    {
        zoomOut.setEnabled(false);
        // or u can change drawable and disable click
    }
    if(mapView.getZoomLevel()==18) {
        zoomIn.setEnabled(false);
        // or u can change drawable and disable click
    }
}

EDIT:



回答2:

I solved the problem this way: disabled built in zoom controls (setBuiltInZoomControls(false)), added my own buttons to UI and added handlers for click on button events.