为什么当mMapFragment不为null时返回null?
View zoom = mMapFragment.getView().findViewById(0x1);
我需要将缩放按钮移动到相应的一侧
if (zoom != null && zoom.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
// ZoomControl is inside of RelativeLayout
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) zoom.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);
zoom.setLayoutParams(params);
}
答案 0 :(得分:0)
使用GoogleMap和MapView代替SupportMapFragment:
XML:
<com.google.android.gms.maps.MapView
android:id="@+id/map1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</com.google.android.gms.maps.MapView>
Java onCreateView函数:
MapView mapView = (MapView) v.findViewById(R.id.mapaPrincipal);
GoogleMap map = mapView.getMap();
注意:你可以定义&#34; mapView&#34;和&#34;地图&#34;作为全局变量,并在onCreateView()
中初始化后在所有函数中使用它