When an app use map and design some layout on this map (TextView, Button or image), developer needs to change position of default buttons of map view. (MyLocationButton, ZoomControl or compass...) As far as i know, there are two possible way for changing position of myLocationButton's position.
1- * - Disable it
* - Create new button programmatically
* - Add animateCamera(toCurrentLocation) to onClickListener of this button
* - And place it wherever you want
But if you don't want to write all that there is a hack for that.
2 - * - findViewById() of hardcoded button with;
// Find map fragment
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
// Find myLocationButton view
View myLocationButton = mapFragment.getView().findViewById(0x2);
if (myLocationButton != null && myLocationButton.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
// ZoomControl is inside of RelativeLayout
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) myLocationButton.getLayoutParams();
// Align it to - parent BOTTOM|LEFT
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
// Update margins, set to 10dp
final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
getResources().getDisplayMetrics());
params.setMargins(margin, margin, margin, margin);
myLocationButton.setLayoutParams(params);
}
But this is not a good solution but it works for me. On the otherhand it can be change every new build of google play service. Do a lot of test before implement this.
I hope this works for you.
Here some more discussion on that topic...
https://code.google.com/p/gmaps-api-issues/issues/detail?id=4670
http://stackoverflow.com/questions/14489880/how-to-change-the-position-of-maps-apis-get-my-location-button
http://stackoverflow.com/questions/14299435/mylocation-button-hidden-behind-transparent-action-bar-how-to-reposition/15740101#15740101
http://stackoverflow.com/questions/14071230/android-maps-library-v2-zoom-controls-custom-position
1- * - Disable it
* - Create new button programmatically
* - Add animateCamera(toCurrentLocation) to onClickListener of this button
* - And place it wherever you want
But if you don't want to write all that there is a hack for that.
2 - * - findViewById() of hardcoded button with;
ZoomControl id = 0x1
MyLocation button id = 0x2
* - And do whatever you want:// Find map fragment
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
// Find myLocationButton view
View myLocationButton = mapFragment.getView().findViewById(0x2);
if (myLocationButton != null && myLocationButton.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
// ZoomControl is inside of RelativeLayout
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) myLocationButton.getLayoutParams();
// Align it to - parent BOTTOM|LEFT
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
// Update margins, set to 10dp
final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
getResources().getDisplayMetrics());
params.setMargins(margin, margin, margin, margin);
myLocationButton.setLayoutParams(params);
}
But this is not a good solution but it works for me. On the otherhand it can be change every new build of google play service. Do a lot of test before implement this.
I hope this works for you.
Here some more discussion on that topic...
https://code.google.com/p/gmaps-api-issues/issues/detail?id=4670
http://stackoverflow.com/questions/14489880/how-to-change-the-position-of-maps-apis-get-my-location-button
http://stackoverflow.com/questions/14299435/mylocation-button-hidden-behind-transparent-action-bar-how-to-reposition/15740101#15740101
http://stackoverflow.com/questions/14071230/android-maps-library-v2-zoom-controls-custom-position
Comments
Post a Comment