If you read the earlier Article in which I talked about the BackStack then you might have noticed the following code in the MainActivity layout file.
<FrameLayout
android:layout_width=”0dp”
android:layout_weight=”3″
android:layout_height=”match_parent”
android:id=”@+id/detailFragmentId”
/>
I mentioned that using a FrameLayout instead of a Fragment element is helpful if we want to replace the current fragment with another one.
In our scenario when a user will click on an Employee then the Employee detail will appear, which means the detail fragment will be replaced with a new instance every time.
You can refer to the Source Code here
One thought on “Learn why to use a FrameLayout instead of Fragment in Layout XML”