Android DialogFragment上的SupportMapFragment
我需要在Android DialogFragment上的SupportMapFragment,android,dialog,google-maps-android-api-2,supportmapfragment,Android,Dialog,Google Maps Android Api 2,Supportmapfragment,我需要在对话框中嵌入SupportMapFragment。这是我能想到的最好的: public class SupportMapFragmentDialog extends DialogFragment { private final SupportMapFragment fragment; public SupportMapFragmentDialog() { fragment = new SupportMapFragment(); setT
对话框中嵌入SupportMapFragment
。这是我能想到的最好的:
public class SupportMapFragmentDialog extends DialogFragment {
private final SupportMapFragment fragment;
public SupportMapFragmentDialog() {
fragment = new SupportMapFragment();
setTargetFragment(fragment, 1);
}
@Override
public View onCreateView(final LayoutInflater inflater,
final ViewGroup container, final Bundle savedInstanceState) {
return fragment.onCreateView(inflater, container, savedInstanceState);
}
public SupportMapFragment getFragment() {
return fragment;
}
}
然而,当我称之为:
final SupportMapFragmentDialog dialog = new SupportMapFragmentDialog();
dialog.show(getSupportFragmentManager(), "Historico");
我明白了:
如何在对话框上查看地图
该应用程序还有另一个SupportMapFragment
正在发挥作用,因此它与配置无关。最后,我在一个常规的对话框中使用了MapView
,而不是SupportMapFragment
这是我的代码:
final Historico h = adapter.getItem(arg2 - 1);
if (mv.getParent() != null) {
((ViewGroup) mv.getParent()).removeView(mv);
}
final Dialog d = new Dialog(HistorialScreen.this);
d.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
d.requestWindowFeature(Window.FEATURE_NO_TITLE);
d.setContentView(mv);
mv.getMap().clear();
mv.getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(h.getPosicion(), 17));
final MarkerOptions options = new MarkerOptions();
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN));
options.position(h.getPosicion());
mv.getMap().addMarker(options);
d.show();
它可以按预期工作。您可以通过此按钮在对话框中显示地图片段
public class DialogMapFragment extends DialogFragment {
private SupportMapFragment fragment;
public DialogMapFragment() {
fragment = new SupportMapFragment();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.mapdialog, container, false);
getDialog().setTitle("");
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.add(R.id.mapView, fragment).commit();
return view;
}
public SupportMapFragment getFragment() {
return fragment;
}
}
R.layout.mapdialog:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp" >
<FrameLayout
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</RelativeLayout>
日志中是否有错误显示?否。什么都没有。