您好我在这行的一个问题,我不知道为什么无法加载片段
FragmentManager manager = getFragmentManager();
FragmentTransaction trans = manager.beginTransaction();
trans.replace(R.id.containerr,new FragmentLastComments());
trans.commit();
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/containerr"
android:layoutDirection="ltr">
</RelativeLayout>
片段XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="ltr">
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginTop="55dp"
android:orientation="vertical">
<TextView
android:id="@+id/txt_lastcomments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="20dp"
android:layout_marginBottom="10dp"
android:text="last comments" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:id="@+id/rv_lastcomments"/>
</LinearLayout>
</RelativeLayout>
该行没有工作
trans.replace(R.id.containerr,new FragmentLastComments());
当我删除此行,我没有得到任何的问题,但是当我使用这条线我得到的问题,我觉得这里的问题
R.id.containerr
我希望有人能帮助我解决这个
u能张贴的错误? – Raghavendra
试试解决方案https://stackoverflow.com/questions/14810348/android-fragment-replace-doesnt-replace-content-puts-it-on-top – Raghavendra
https://i.stack.imgur.com/avPHl。 png – ShWaEkI