Android 碎片出现在另一个碎片的顶部

Android 碎片出现在另一个碎片的顶部,android,android-fragments,Android,Android Fragments,我有一个选项卡式Android应用程序,它在选项卡的每个页面上使用片段。我在一个片段里面有一个按钮,我用这个按钮把另一个片段带到屏幕上。当按下按钮时,您可以看到第二个片段。唯一的问题是,第二个片段出现在第一个片段上方,使得第二个片段中的文本无法读取,因为第一个片段中的文本在后面。当第二个片段出现时,如何让第一个片段消失 下面是按钮侦听器的代码 @Override public void onClick(View v) { Fragment frag = new ContactsFragment(

我有一个选项卡式Android应用程序,它在选项卡的每个页面上使用片段。我在一个片段里面有一个按钮,我用这个按钮把另一个片段带到屏幕上。当按下按钮时,您可以看到第二个片段。唯一的问题是,第二个片段出现在第一个片段上方,使得第二个片段中的文本无法读取,因为第一个片段中的文本在后面。当第二个片段出现时,如何让第一个片段消失

下面是按钮侦听器的代码

@Override
public void onClick(View v) {
Fragment frag = new ContactsFragment(); 
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.fragment_container, frag);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null);
ft.commit();
}

尝试将根视图的第二个
片段
背景设置为所需颜色

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">

<TextView
    android:text="Hi"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</RelativeLayout>


在添加第一个片段的地方张贴代码。使用R.id.fragment\u容器的第一个片段是什么?还是别的?@uDevel第一个片段使用R.id.fragment\u容器。