Learn why to use a FrameLayout instead of Fragment in Layout XML

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

Author: androidsmartly

I am a Tech Enthusiast who likes to work on new Ideas. Sharing knowledge on Android, Marketing, Startups and More.

1 thought on “Learn why to use a FrameLayout instead of Fragment in Layout XML”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s