È stato un po 'faticoso farlo funzionare. Ma l'ho fatto e nel processo ho anche iniziato a spostare i pulsanti di zoom. Qui il mio codice completo:
package com.squirrel.hkairpollution;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.UiSettings;
import com.google.android.gms.maps.model.LatLng;
public class MySupportMapFragment extends SupportMapFragment {
private static final String TAG = HKAirPollution.TAG;
public MySupportMapFragment() {
return;
}
@Override
public View onCreateView(LayoutInflater arg0, ViewGroup arg1, Bundle arg2) {
Log.v(TAG, "In overridden onCreateView.");
View v = super.onCreateView(arg0, arg1, arg2);
Log.v(TAG, "Initialising map.");
initMap();
return v;
}
@Override
public void onViewCreated (View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
resetButtons();
}
private void initMap(){
UiSettings settings = getMap().getUiSettings();
settings.setAllGesturesEnabled(true);
settings.setMyLocationButtonEnabled(true);
LatLng latLong = new LatLng(22.320542, 114.185715);
getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(latLong,11));
}
private void resetButtons()
{
ViewGroup v1 = (ViewGroup)this.getView();
ViewGroup v2 = (ViewGroup)v1.getChildAt(0);
ViewGroup v3 = (ViewGroup)v2.getChildAt(0);
ViewGroup v4 = (ViewGroup)v3.getChildAt(1);
View position = (View)v4.getChildAt(0);
int positionWidth = position.getLayoutParams().width;
int positionHeight = position.getLayoutParams().height;
RelativeLayout.LayoutParams positionParams = new RelativeLayout.LayoutParams(positionWidth,positionHeight);
int margin = positionWidth/5;
positionParams.setMargins(0, 0, 0, margin);
positionParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
positionParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
position.setLayoutParams(positionParams);
View zoom = (View)v4.getChildAt(2);
int zoomWidth = zoom.getLayoutParams().width;
int zoomHeight = zoom.getLayoutParams().height;
RelativeLayout.LayoutParams zoomParams = new RelativeLayout.LayoutParams(zoomWidth, zoomHeight);
zoomParams.setMargins(0, 0, 0, margin);
zoomParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
zoomParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
zoom.setLayoutParams(zoomParams);
}
}