How to ensure the zoom control always displayed on MapView?

I have terrible problems with this. I have a MapView, in my activity I set a flag to display magnification controls, and it works. But then the user moves on to another action, returns to the map, and the zoom controls are gone.

Is there an easy way to ensure that zoom controls are always present, or do I need to roll myself up from above? Ideally, I want to set up the zoom controls in a subclass of MapView to make things simple. I suspect that it does not work when the zoom controls are set at the wrong time, but when is the right time?

+4
source share
2 answers

That's what I'm doing. First add the ZoomControl view to the file using MapView (I use RelativeLayout to store MapView and ZoomControls)

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <MapView android:id="@+id/map" android:layout_width="fill_parent" android:layout_height="fill_parent" android:apiKey="X" android:clickable="true" /> <ZoomControls android:id="@+id/zoomcontrols" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" /> </RelativeLayout> 

Now in your onCreate method do something like

  mapView.setBuiltInZoomControls(false); ZoomControls zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols); zoomControls.setOnZoomInClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mapController.zoomIn(); } }); zoomControls.setOnZoomOutClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mapController.zoomOut(); } }); 
+3
source

You can do it very easily. In the onCreate() method, do the following:

 MapView mapView = (MapView) findViewById(R.id.map_view_id); mapView.setBuiltInZoomControls(true); 

In this case, the zoom buttons are displayed at the bottom of the screen. They disappear if now touch events occur within a short period of time, and they appear automatically again if any touch events occur.

0
source

Source: https://habr.com/ru/post/1380400/


All Articles