私はこのフォームなぜ私のフラグメントがお互いの上に現れるのですか?
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/fragment1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/fragment2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
の主なレイアウトを持っていると私は、次のXMLを使用する2つのフラグメントを呼び出すために、それらの両方に.replace()
を呼び出すFragmentTransactionをしています:Fragment1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="true">
...
</LinearLayout>
フラグメント2.xml
なぜ2つの断片がお互いの上に現れるのですか? RecraglerViewがあるFragment2のすぐ上にFragment1を表示します。
編集:置換コード:
fragment1 = Fragment1.newInstance();
fragment2 = Fragment2.newInstance();
FragmentManager fragmentManager = getChildFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment1, fragment1, "fragment1");
fragmentTransaction.replace(R.id.fragment2, fragment2, "fragment2");
fragmentTransaction.commit();
これは間違っているのですか、置き換え以外のものを使用する必要がありますか? – KaliMa
Fragmentをどのように追加したのかを示すコードを表示し、さらに明確にするためのスクリーンショットも表示します。 – Enzokie
@Enzokieいくつかのコードを追加しました – KaliMa