我要做的是拥有一个主/细节风格的应用程序,其中一个选择器选项是Google地图,地图布局下方有一些额外的按钮。
我的所有其他选项只是将片段加载到FrameLayout中,使用类似:
getSupportFragmentManager().beginTransaction()
.replace(R.id.content, myFragment, fragTag)
.commit();
我不能用MapFragment做到这一点,因为我需要布局中的其他东西,并且不支持嵌套的片段(但希望如此)。所以,我需要用包含片段的复合视图替换常规片段,但我不确定片段管理应该如何工作。
我认为我不能打电话
getSupportFragmentManager().beginTransaction()
.replace(R.id.content, myCompositeView, fragTag)
.commit();
目前我正在这样做:
Fragment currentFrag = getSupportFragmentManager().findFragmentById(R.id.content);
getSupportFragmentManager().beginTransaction().remove(currentFrag);
LayoutInflater inflator = LayoutInflater.from(this);
ViewGroup container = (ViewGroup)findViewById(R.id.content);
container.removeAllViews();
View mapView = inflator.inflate(R.layout.store_finder, container, true);
由于我需要再次从布局中删除所有视图,因此在将其替换为其他片段时会使其变得有点混乱。此外,我不确定如何在设置之后正确删除MapFragment。
我会感激任何帮助,并感谢有人放下心来:)
脚注:显然嵌套片段现在已成为一种东西,但不确定这是我想要的简单方法。 http://developer.android.com/about/versions/android-4.2.html#NestedFragments
答案 0 :(得分:0)
支持嵌套片段,请参阅:
http://developer.android.com/reference/android/app/Fragment.html#getChildFragmentManager()
我在当前的应用/项目中使用它们并且效果很好。不确定在映射视图中使用它们是否还有其他约束?
// WildStyle