gpt4 book ai didi

android - DialogFragment 上的 SupportMapFragment

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:43:30 24 4
gpt4 key购买 nike

我需要在Dialog 中嵌入一个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");

我明白了:

enter image description here

我该怎么做才能在对话框中看到 map ?

该应用程序有另一个 SupportMapFragment 可以创造奇迹,因此它与配置没有任何关系。

最佳答案

你可以通过这个在对话框中显示 map fragment

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>

关于android - DialogFragment 上的 SupportMapFragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16963019/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com