Member-only story

FragmentContainerView

Satya Pavan Kantamani
3 min readJul 1, 2020

--

Learn how to add fragments into FragmentContainerView

Photo by Markus Winkler on Unsplash

History

Usually in Android, before NavGraph if we want to add a fragment dynamically we used to add container layout mostly FrameLayout in the XML and then add the required instance to the container using fragment manager. We used to use different kinds of layouts before but none of these layouts are optimized for fragment transactions or fragments stuff. As the fragments usage has become a common thing in every app to simplify that and to optimize the fragments stuff Android team came up with FragmentContainerView. In this post let’s check out what is FragmentContainerView and how to use it.

What is FragmentContainerView?

FragmentContainerView is basically a custom view designed extending FrameLayout. In simple terms, we can say FragmentContainerView is a custom layout designed specifically for dealing with fragments. As it was extending FramLayout it can reliably handle Fragment Transactions and has some more additional features related to fragment behavior. Unlike other ViewGroups, it only handles attributes related to fragments. So we should not use FragmentContainerView as a replacement for other ViewGroups (FrameLayout, LinearLayout, etc) outside of Fragment use cases.

Attempting to add any other view other than fragments…

--

--

Satya Pavan Kantamani
Satya Pavan Kantamani

Written by Satya Pavan Kantamani

Android Dev, Interested in Traveling, App development. Based in Hyderabad, India. Catch me at https://about.me/satyapavankumar

No responses yet