如何以编程方式添加地图片段 [英] How to add map fragment programmatically
本文介绍了如何以编程方式添加地图片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想以编程方式将此xml片段添加到其他片段。
是否有可能?
I would like add this xml fragment programmatically to other fragments. Is it possible?
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
推荐答案
在XML中,您可以添加一个占位符容器:
In XML you can add a placeholder container:
<FrameLayout
android:id="@+id/mapContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
然后在代码中你可以这样做:
And then in code you can do:
FragmentManager fm = getChildFragmentManager();
SupportMapFragment supportMapFragment = SupportMapFragment.newInstance();
fm.beginTransaction().replace(R.id.mapContainer, supportMapFragment).commit();
这篇关于如何以编程方式添加地图片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文