How can i customize the position of the builtin zoom controls in a GoogleMap V2 ?
There are a lot of questions related to this topic for the Version 1 of Google Maps library.
Placing Zoom Controls in a MapView
How to reposition built-in zoom controls in MapView?
How to layout zoom Control with setBuiltInZoomControls(true)?
However, i wasn't able to find any questions in relation to the V2 of the library.
In the V2, there's no method
(LinearLayout) mapView.getZoomControls();
all the previously mentioned questions becomes obsolete.
Thanks in advance
Depending on what you're trying to do, you might find GoogleMap.setPadding() useful (added in September 2013).
map.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
From the API docs:
This method allows you to define a visible region on the map, to signal to the map that portions of the map around the edges may be obscured, by setting padding on each of the four edges of the map. Map functions will be adapted to the padding. For example, the zoom controls, compass, copyright notices and Google logo will be moved to fit inside the defined region, camera movements will be relative to the center of the visible region, etc.
Also see the description of how padding works in GoogleMap.
Yes, you can change position of ZoomControl and MyLocation button with small hack.
In my sample I have SupportMapFragment, which is inflated from xml layout.
View ids for ZoomControl and MyLocation button:
ZoomControl id = 0x1
MyLocation button id = 0x2
Code to update ZoomControl position:
// Find map fragment
SupportMapFragment mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.map);
// Find ZoomControl view
View zoomControls = mapFragment.getView().findViewById(0x1);
if (zoomControls != null && zoomControls.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
// ZoomControl is inside of RelativeLayout
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) zoomControls.getLayoutParams();
// Align it to - parent top|left
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
// Update margins, set to 10dp
final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
getResources().getDisplayMetrics());
params.setMargins(margin, margin, margin, margin);
}
I use MapFragment not SupportMapFragment:
import android.util.TypedValue;
in onCreate
// Find map fragment
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.mapview);
int ZoomControl_id = 0x1;
int MyLocation_button_id = 0x2;
// Find ZoomControl view
View zoomControls = mapFragment.getView().findViewById(ZoomControl_id);
if (zoomControls != null && zoomControls.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
// ZoomControl is inside of RelativeLayout
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) zoomControls.getLayoutParams();
// Align it to - parent top|left
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
// Update margins, set to 10dp
final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
getResources().getDisplayMetrics());
params.setMargins(margin, margin, margin, margin);
}
Just for the record:
Navigation-controls are 0x4
So in total:
#LayoutRes final int ZOOM_CONTROL_ID = 0x1;
#LayoutRes final int MY_LOCATION_CONTROL_ID = 0x2;
#LayoutRes final int NAVIGATION_CONTROL_ID = 0x4;
Related
Interesting one this.
So we have a "Details" view that is shown over a GoogleMap, and for Tablets this activity is forced to be styled like a dialog.
This details view has a GoogleMap within it.
This works fine within our Nexus 10, however the Galaxy Note 10 2 (4.0.1) is having some real issues with this approach.
Graphically the ActionBar title and Home Icon and being made transparent, and also the Map in the Details view is being dimmed somewhat.
Has anyone come across this type of issue before? I can't seem to find anything around this.
Thanks
Make activity into "dialog" code
#SuppressLint("InlinedApi")
private static void makeActivityIntoDialog(Activity activity) {
//To show activity as dialog and dim the background, you need to declare android:theme="#style/PopupTheme" on for the chosen activity on the manifest
//This will only be called for tablets over v11 so we are ok to ignore this warning
activity.requestWindowFeature(Window.FEATURE_ACTION_BAR);
activity.setFinishOnTouchOutside(true);
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
LayoutParams params = activity.getWindow().getAttributes();
DisplayMetrics dm = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
if (dm.heightPixels < dm.widthPixels){
params.height = (4 * dm.heightPixels)/ 5 ; //relative height
params.width = (4 * dm.widthPixels)/ 7 ; //relative width
}else{
params.height = (3 * dm.heightPixels)/ 5 ; //relative height
params.width = (5 * dm.widthPixels)/ 7 ; //relative width
}
params.alpha = 1.0f;
params.dimAmount = 0.5f;
activity.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
}
I have got it down to these lines of code which is causing the actionbar graphical error.
mMapFragment = new SupportMapFragment();
if (mMapFragment.isAdded()){
getFragmentManager().beginTransaction().attach(mMapFragment);
}else{
getFragmentManager().beginTransaction().add(R.id.google_map_fragment_container, mMapFragment).commit();
}
Basically the second i Add the GoogleMap Fragment to the view the action bar gets buggery.
The answer was to place the map within a transparent frame layout - not sure why but it now does not cut out that strange transparent square from the title bar.
static public class WorkaroundMapFragment extends SupportMapFragment {
public WorkaroundMapFragment() {
super();
}
#Override
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle savedInstance) {
View layout = super.onCreateView(layoutInflater, viewGroup, savedInstance);
layout.requestFocus();
FrameLayout frameLayout = new FrameLayout(getActivity());
frameLayout.setBackgroundColor(getResources().getColor(android.R.color.transparent));
((ViewGroup) layout).addView(frameLayout,
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
return layout;
}
}
}
I am writing an application in android using Google map-V2 API. I want to over lay action bar just as in the Google map application. And I enabled "My Location " button. The problem now is that my location button is under the action bar. Is there any way to re-position this button. I want to make an app some what similar to Maps. I am new to android so please help.
You can set padding to the map.
This solved the problem - overlays over the map on the top (I used 48 dips, but you can overlay action bar and then get actual height of it (?android:attr/actionBarSize))
mapFragment.getMap().setPadding(0, dpToPx(48), 0, 0);
(DP to PX function is from this SO answer)
You can reposition your location button easily
View plusMinusButton = suppormanagerObj.getView().findViewById(1);
View locationButton = suppormanagerObj.getView().findViewById(2);
// and next place it, for exemple, on bottom right (as Google Maps app)
RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) locationButton.getLayoutParams();
// position on right bottom
rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
you can also set padding after setting alignment of the location button
mMap.setPadding(0, 0, 30, 105);
You can not alter the MyLocationButton in any way, but enable and disable it. There is already a request for this.
Feel free to disable the button and just implement your own one.
You would have something like this:
mMap.getUiSettings().setMyLocationButtonEnabled(false);
I solved this problem in my map fragment by re positioning my location button to the right bottom corner of view using code below,
here is my Maps Activity.java :-
add this lines of code in onCreate() method,
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapView = mapFragment.getView();
mapFragment.getMapAsync(this);
and here is onMapReady() code :-
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMyLocationEnabled(true);
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
if (mapView != null &&
mapView.findViewById(Integer.parseInt("1")) != null) {
// Get the button view
View locationButton = ((View) mapView.findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("2"));
// and next place it, on bottom right (as Google Maps app)
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)
locationButton.getLayoutParams();
// position on right bottom
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
layoutParams.setMargins(0, 0, 30, 30);
}
}
I hope, this will solve your problem. Thanks.
Instead of the findViewById solutions, I used the findViewWithTag to get a reference to the button. Using a string seemed more readable and reliable to me.
View myLocationButton = mMap.findViewWithTag("GoogleMapMyLocationButton");
RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) myLocationButton.getLayoutParams();
rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
Just use GoogleMap.setPadding(left, top, right, bottom), which allows you to indicate parts of the map that may be obscured by other views. Setting padding re-positions the standard map controls, and camera updates will use the padded region.
https://developers.google.com/maps/documentation/android/map#map_padding
This question already has answers here:
Change position of Google Maps API's "My location" button
(17 answers)
Closed 4 years ago.
I have added a map fragment (API v2) to my app with the map covering the whole screen and a semi-transparent actionbar on top.
The activity uses a theme with android:windowActionBarOverlay set to true.
I have also enabled the "MyLocationButton" on the map, but since the map covers the full height of the screen, the button is covered by the action bar.
How can I make the map fragment draw the location button below the action bar or at the bottom of the screen instead?
Instead of creating your own button, just move the build in button according to the action bar size.
This code works for me and the button is just where the button should be (like in google maps):
// Gets the my location button
View myLocationButton = getSherlockActivity().findViewById(R.id.MainContainer).findViewById(2);
// Checks if we found the my location button
if (myLocationButton != null){
int actionBarHeight = 0;
TypedValue tv = new TypedValue();
// Checks if the os version has actionbar in it or not
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
if (getSherlockActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
}
// Before the action bar was added to the api
else if(getSherlockActivity().getTheme().resolveAttribute(com.actionbarsherlock.R.attr.actionBarSize, tv, true)){
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
}
// Sets the margin of the button
ViewGroup.MarginLayoutParams marginParams = new ViewGroup.MarginLayoutParams(myLocationButton.getLayoutParams());
marginParams.setMargins(0, actionBarHeight + 20, 20, 0);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(marginParams);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
myLocationButton.setLayoutParams(layoutParams);
}
Just put this code in the onActivityCreated (if you will put it in the onCreateOptionsMenu, it will not support version before 3.0 - because the life cycle there is different.
Another thing, the "R.id.MainContainer" is the container of the map fragment.
I'm using ActionBar Sherlock, but it will work also for regular action bar with a few modifications..
Below (especially in fixMapControlLocations) i've addressed this with ActionBarSherlock.
Issues I had were on narrow screens, and the split action bar having the wrong offset depending on rotation. The isNarrow check through sherlock lets me know if its narrow.
Another key change is i'm setting the padding of the myLocation's parent's parent view. This picks up all controls inside, and based on hierarchyviewer is how google maps is doing it. The Google attribution logo is on the next parent up the tree in a Surface object. Not looking like that is easily movable, so i'm probably just going to end up loosing the bottom action bar's transparency effect to stay in compliance.
protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
setUpMapIfNeeded();
getSupportActionBar().setBackgroundDrawable(d);
getSupportActionBar().setSplitBackgroundDrawable(d);
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the
// map.
if (map == null) {
// Try to obtain the map from the SupportMapFragment.
map = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getExtendedMap();
// Check if we were successful in obtaining the map.
if (map != null) {
setUpMap();
}
}
}
private void setUpMap() {
fixMapControlLocations();
.....
}
private void fixMapControlLocations() {
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
int actionBarHeight = 0;
TypedValue tv = new TypedValue();
if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
{
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
}
View myLocationParent = ((View)mapFragment.getView().findViewById(1).getParent());
View myLocationParentParent = ((View)myLocationParent.getParent());
myLocationParentParent.setPadding(0, actionBarHeight, 0, isNarrow()?actionBarHeight:0);
}
public boolean isNarrow() {
return ResourcesCompat.getResources_getBoolean(getApplicationContext(),
R.bool.abs__split_action_bar_is_narrow);
}
You can accomplish this with the recently-added GoogleMap.setPadding() method:
map.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
From the API docs:
This method allows you to define a visible region on the map, to signal to the map that portions of the map around the edges may be obscured, by setting padding on each of the four edges of the map. Map functions will be adapted to the padding. For example, the zoom controls, compass, copyright notices and Google logo will be moved to fit inside the defined region, camera movements will be relative to the center of the visible region, etc.
Also see the description of how padding works in GoogleMap.
This has already been filed as an enhancement (please star it if you haven't already) http://code.google.com/p/gmaps-api-issues/issues/detail?id=4670
As a temporary workaround I have added my own find location button below the actionbar (my map fragment is in a RelativeLayout so I just did alignParentRight and set appropriate margin top).
Then in my onClickHandler I did this:
public void onClickHandler(View target) {
switch (target.getId()) {
case R.id.my_fml_btn:
mMap.setMyLocationEnabled(true);
View fmlBtn = mMapWrapper.findViewById(2); //mMapWrapper is my RelativeLayout
if (fmlBtn != null) fmlBtn.setVisibility(View.INVISIBLE);
break;
}
}
I used hierarchyviewer to find the id of the button that was added by the maps api. It just happens to be the 2nd view added to the map (and set to invisible).
You can of course you can fiddle about with LayoutParams to offset this button rather than hide it but this button only appears after you setMyLocationEnabled to true! (in my use case I prefer to let the user decide before firing up the gps)
Make sure you use ?android:attr/actionBarSize (or ?attr/actionBarSize if you're using ActionBarSherlock) to correctly offset the content of the fragment.
Depending of the effect you're trying to accomplish, either apply this value as margin or padding. I'm guessing that because of the semi-transparant ActionBar, you'll want to try padding, in order to still have the map appear behind it (and keep the see-through effect). I'm just not 100% sure whether padding will actually move the 'Locate me' button down... If not, then probably applying a margin is your only other option.
See here for an example and more details on this attribute.
would like to add a zoom control to the map. I also want to layout the position of the zoom Control instead of the default middle bottom position. I can do this by getZoomControl but it is deprecated.
Could anyone tell me how to do this with setBuildtInZoomControls?
This is how I got mine working finally (by embedding a ZoomControl in XML layout).
mapView = (MapView) this.findViewById(R.id.mapView);
ZoomControls zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols);
zoomControls.setOnZoomInClickListener(new OnClickListener() {
public void onClick(View v) {
mapView.getController().zoomIn();
}
});
zoomControls.setOnZoomOutClickListener(new OnClickListener() {
public void onClick(View v) {
mapView.getController().zoomOut();
}
});
See: Always show zoom controls on a MapView
mapView.getZoomButtonsController()
Although this is undocumented (at least in the javadoc available here: com.google.android.maps) I am quite sure this is the replacement for the deprecated getZoomControls
Edit: just found out that it is documented, just not in the google api docs but rather here: ZoomButtonsController on developer.android.com
You could then call getContainer () or getZoomControls () (depending on what you want to do) to get access to the zoom controls view.
And then do something like
RelativeLayout.LayoutParams zoomParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
zoomParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
mapView.getZoomButtonsController().getZoomControls().setLayoutParams(zoomParams);
although I have to admit that I am not sure what layout the maps view uses, could be LinearLayout as well.
LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.layout_zoom);
View mapController = mapView.getZoomButtonsController().getZoomControls();
zoomLayout.addView(mapController, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
I'm pretty sure that the only way to do this is to either use the MapView's deprecated getZoomControls() or to DIY it. The MapController has the methods necessary (e.g. zoomIn() and zoomOut()).
RelativeLayout relativeLayout = new RelativeLayout(this);
setContentView(relativeLayout);
final MapView mapView = new MapView(this, DEBUG_MAP_API_KEY);
RelativeLayout.LayoutParams mapViewLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,RelativeLayout.LayoutParams.FILL_PARENT );
relativeLayout.addView(mapView, mapViewLayoutParams);
RelativeLayout.LayoutParams zoomControlsLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT );
zoomControlsLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
zoomControlsLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
relativeLayout.addView(mapView.getZoomControls(), zoomControlsLayoutParams);
mapView.setClickable(true);
mapView.setEnabled(true);
I think this should work ... Hope this is useful :)
The solution provided by George on Placing Zoom Controls in a MapView allows to layout the built in zoom controls by using gravity attributes. This attribute positions the element into its container which seems that is positioned on the bottom of the screen so its not possible to position the zoom controls on the top of the screen by layouting the zoom controls.
In conclusion you can layout the built in zoom controls by doing:
((FrameLayout.LayoutParams) mapView.getZoomButtonsController().getZoomControls().getLayoutParams()).gravity = Gravity.RIGHT;
Remember that the zoom controls are contained into a FrameLayout therefore any try to use rules like RelativeLayout.ALIGN_PARENT_BOTTOM or RelativeLayout.ALIGN_PARENT_TOP will lead you only to pain and sorrow.
I'm trying to get the zoom controls to show up in a mapview, the following code almost works, but the zoom controls appear in the top left of the mapview, not the bottom center like I'm specifying via setGravity(). Can someone enlighten me as to what I'm missing?
zoomView = (LinearLayout) mapView.getZoomControls();
zoomView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT));
zoomView.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
mapView.addView(zoomView);
These views/layouts are all constructed programmatically, there is no layout file to tweak.
Add the following line to the OnCreate() method of your MapView Class:
view.setBuiltInZoomControls(true);
The trick here is to place another Layout container where you want to put the ZoomControls and then insert the ZoomControls into that.
The real trick is to use the RelativeLayout rather than LinearLayout to position the elements, as shown in this sample layout.xml:
<?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">
<com.google.android.maps.MapView
android:id="#+id/myMapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="MY_MAP_API_KEY"
/>
<LinearLayout android:id="#+id/layout_zoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
The layout_zoom LinearLayout element is positioned in the bottom center of the screen, placing it over the middle/bottom of the MapView.
Then within your Activity's onCreate, get a reference to the layout_zoom element and insert the ZoomControl into it, much like you've already done:
LinearLayout zoomLayout =(LinearLayout)findViewById(R.id.layout_zoom);
View zoomView = myMapView.getZoomControls();
zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
myMapView.displayZoomControls(true);
The ZoomControls should now appear on a long click, without stealing the map touch events.
The above didn't work for me, but this does (to place the control on the bottom right):
mapView.setBuiltInZoomControls(true);
ZoomButtonsController zbc = mapView.getZoomButtonsController();
ViewGroup container = zbc.getContainer();
for (int i = 0; i < container.getChildCount(); i++) {
View child = container.getChildAt(i);
if (child instanceof ZoomControls) {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) child.getLayoutParams();
lp.gravity = Gravity.RIGHT | Gravity.BOTTOM;
child.requestLayout();
break;
}
}
Reto : thanks for your reply, but the idea was to do it without using XML layouts.
I eventually worked out the problem. Because a MapView is a subclass of ViewGroup, you can easily add child views (like the zoom controls). All you need is a MapView.LayoutParams instance and you're good to go. I did something like this (puts zoom controls in the bottom center of the mapview).
// layout to insert zoomcontrols at the bottom center of a mapview
MapView.LayoutParams params = MapView.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT,
mapViewWidth / 2, mapViewHeight,
MapView.LayoutParams.BOTTOM_CENTER);
// add zoom controls
mapView.addView(mapView.getZoomControls(), params);
from the google groups thread i found this:
ZoomControls without XML:
public class MyMapActivity extends MapActivity { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RelativeLayout relativeLayout = new RelativeLayout(this);
setContentView(relativeLayout);
final MapView mapView = new MapView(this, DEBUG_MAP_API_KEY);
RelativeLayout.LayoutParams mapViewLayoutParams = new
RelativeLayout.LayoutParams
(RelativeLayout.LayoutParams.FILL_PARENT,RelativeLayout.LayoutParams.FILL_PARENT );
relativeLayout.addView(mapView, mapViewLayoutParams);
RelativeLayout.LayoutParams zoomControlsLayoutParams = new
RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT );
zoomControlsLayoutParams.addRule
(RelativeLayout.ALIGN_PARENT_BOTTOM);
zoomControlsLayoutParams.addRule
(RelativeLayout.CENTER_HORIZONTAL);
relativeLayout.addView(mapView.getZoomControls(),
zoomControlsLayoutParams);
mapView.setClickable(true);
mapView.setEnabled(true);
}
was 100% working for me with SDK1.1
Unfortunately I cant add a comment to Jason Hudgins approved solution from Nov 28 at 6:32 but I got a tiny error with his code:
In this line:
MapView.LayoutParams params = MapView.LayoutParams(
The error Eclipse gave me was
"The method LayoutParams(int, int,
int, int, int) is undefined for the
type MapView"
instead, creating a new MapView.LayoutParams object fixed it, like this:
MapView.LayoutParams params = **new** MapView.LayoutParams(
It took me some time to find out, as I am a n00b :D
You can try this:
MapView map = (MapView)findViewById(R.id.mapview);
map.setBuiltInZoomControls(true);
Reto - the problem with using FILL_PARENT is that the zoom control then "steals" all of the touch events; so that you can't pan the map while the zoom controls are visible. Do you know how to prevent this?