更换后片段仍然可见

时间:2016-02-10 11:50:02

标签: android android-fragments

我在这里看了一遍,几乎尝试了一切。我的主要活动包含我的工具栏和TabLayout,这会加载一个名为ActiveThreadFragment的片段。然后我将ActiveThreadFragment替换为另一个名为PostFragment的。以下是发生的问题: PostFragment Overlapping ActiveThreadFragment

这是我用PostFragment替换ActiveThreadFragment的代码

private void showItemSelectedAtPosition(int position) {
    Threads selectedThread = mData.getItem(position);
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(R.id.content_thread,
            PostFragment.newInstance(selectedThread.getThreadItem()));
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commitAllowingStateLoss();
}

这是ActiveThreadFragment的布局,其中FrameLayout' content_thread'是用它代替。

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="2"
    android:background="@color/primaryColor">

    <FrameLayout
        android:id="@+id/content_thread"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:padding="15dp"
        android:id="@+id/threadRecyclerView"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="1.7"/>

    </LinearLayout>

我做错了什么并且无法弄清楚吗?我真的很傻吗?如果需要,我可以提供更多代码或其他任何东西。

0 个答案:

没有答案