我一直在尝试将谷歌地图上的“我的位置”按钮左对齐,因为它默认右对齐。
我在这里看到了解决方案代码,但没有多大帮助。
并尝试了以下代码:
SupportMapFragment mapFragment = ((SupportMapFragment)
getChildFragmentManager().findFragmentById(R.id.fragmentMap));
View myLocationButton = mapFragment.getView().findViewById(0x2);
if (myLocationButton != null && myLocationButton.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
// location button is inside of RelativeLayout
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) myLocationButton.getLayoutParams();
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);
}