【问题标题】:Android Fragment Not Replacing ProperlyAndroid 片段无法正确替换
【发布时间】:2012-03-03 05:28:20
【问题描述】:

我正在尝试使用片段为 3.0 构建应用程序。在应用程序的左侧有一个静态片段,在右侧有一个动态片段。我在动态部分的每个片段都有一个标题。每当我去替换初始片段时,第一个的标题仍然显示在第一个的标题上方。连续替换替换了下部,但仍显示初始标题(抱歉我还不能发布图片)。

我能为图片做的最好的:

初始标题

新标题

内容(显示正常)

main.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>

用于改变片段的部分 MainActivity

private void open(Fragment toShow)
{
    FragmentTransaction fragmentTransaction = FragMag.beginTransaction();
    fragmentTransaction.replace(R.id.dynamic_fragment, toShow);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
}

如果您需要任何其他信息,请告诉我,并提前感谢您的帮助。

【问题讨论】:

    标签: android android-fragments fragment


    【解决方案1】:

    如果要动态更改片段,则不能在布局中声明它们。 Fragment documentation 有一个示例,我认为您正在描述的内容,其中布局中声明了一个静态片段以及用于保存将动态添加和替换的片段的 FrameLayout。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多