Change <fragment/>
in xml layout to <FrameLayout/>
<FrameLayout android:id="@+id/frag_title" android:visibility="gone" android:layout_marginTop="?android:attr/actionBarSize" android:layout_width="@dimen/titles_size" android:layout_height="match_parent" /> <FrameLayout android:id="@+id/frag_content" android:layout_width="match_parent" android:layout_height="match_parent" />
and programmatically add fragments:
FragmentManager fragmentManager = getFragmentManager() FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); ExampleFragment fragment = new ExampleFragment(); fragmentTransaction.replace(R.id.frag_content, fragment); fragmentTransaction.commit();
But first read this one .
source share