本文介绍了SupportMapFragment on DialogFragment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在对话框中嵌入一个 SupportMapFragment 。这是我能想到的最好的:

I need to embed aSupportMapFragmentin aDialog. This is the best I could think of:

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;
    }

}

但是,当我打电话给:

However, when I call this:

final SupportMapFragmentDialog dialog = new SupportMapFragmentDialog();
dialog.show(getSupportFragmentManager(), "Historico");

我得到这个:

我可以做什么来查看地图上的对话框?

What can I do to see the map on the Dialog?

该应用程序有另一个 SupportMapFragment 这是工作奇迹,所以没有什么

The app has another SupportMapFragment that is working wonders, so it doesn't have anything to do with the configuration.

推荐答案

最后我结束了使用 MapView 在常规对话框而不是 SupportMapFragment

In the end I ended up usingMapViewin a regularDialoginstead ofSupportMapFragment

这是我的代码:

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();

它的工作原理如下。

这篇关于SupportMapFragment on DialogFragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 09:05