Change zoom controls in a MapView

2020-06-21 04:00发布

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:

enter image description here

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

Thanks in advance.

2条回答
地球回转人心会变
2楼-- · 2020-06-21 04:17

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: zoom in zoom out

查看更多
The star\"
3楼-- · 2020-06-21 04:23

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.

查看更多
登录 后发表回答