我正在尝试使用片段构建 3.0 的应用程序。应用程序的左侧有一个静态片段,右侧有一个动态片段。我的动态部分中的每个片段都有一个标题。每当我去替换初始片段时,第一个片段的标题仍然显示在第一个片段的标题上方。连续的替换替换了下部,但仍然显示初始标题(抱歉我还不能发布图像)。
我能为图像做的最好的事情:
初始标头
新标题
内容(显示正常)
主要.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<fragment
android:id="@+id/static_fragment"
android:name="ruleout.android.History_Fragment"
android:layout_width="500dp"
android:layout_height="match_parent" />
<fragment
android:id="@+id/dynamic_fragment"
android:name="ruleout.android.New_Screen_Fragment"
android:layout_width="fill_parent"
android:layout_height="match_parent" />
</LinearLayout>
Partial MainActivity 用于更改片段
private void open(Fragment toShow)
{
FragmentTransaction fragmentTransaction = FragMag.beginTransaction();
fragmentTransaction.replace(R.id.dynamic_fragment, toShow);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
如果您需要任何其他信息,请告诉我,并提前感谢您的帮助。
如果您想动态更改片段,则无法在布局中声明它们。这片段文档有一个例子,我认为您正在描述,其中布局有一个静态片段声明,以及一个用于保存将动态添加和替换的片段的 FrameLayout 。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)