您可以通过从片段中获取当前位置按钮的视图来更改此设置
//Fragment code to change the position of the current location button
private SupportMapFragment mapFragment;
mapFragment = (SupportMapFragment) this.getChildFragmentManager()
.findFragmentById(R.id.map);
@Override
public void onMapReady(GoogleMap googleMap) {
try {
map = googleMap;
if (mapFragment != null &&
mapFragment.getView().findViewById(Integer.parseInt("1")) != null) {
// Get the button view
View locationButton = ((View) mapFragment.getView().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_BOTTOM, RelativeLayout.TRUE);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START, 0);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END, RelativeLayout.TRUE);
layoutParams.addRule(RelativeLayout.CENTER_VERTICAL, 0);
int marginBottom = mNavigationListFragment.llTypeContainer.getHeight() + 5;
int marginRight = (int)convertFromDpToPixel(context, 10);
layoutParams.setMargins(0, 0, marginRight, marginBottom);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static final float convertFromDpToPixel(Context context, float dp) {
float ht_px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics());
return ht_px;
}
要隐藏该按钮,请使用以下代码:
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
map.getUiSettings().setMyLocationButtonEnabled(false);
}