Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is a FrameLayout used for fragments?

Wherever I look, FrameLayout seems to be used as the FragmentContainer. Why is FrameLayout always seen with Fragments?

like image 814
maysi Avatar asked Jul 05 '13 18:07

maysi


2 Answers

You can basically use RelativeLayout or LinearLayout it will still work,but the answer of your question is in FrameLayout's documentation :

FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other. You can, however, add multiple children to a FrameLayout and control their position within the FrameLayout by assigning gravity to each child, using the android:layout_gravity attribute.

You can read more about FrameLayout here : FrameLayout/Android Developers

like image 124
hardartcore Avatar answered Sep 21 '22 06:09

hardartcore


Main purpose of frame layout is to block the area required to fit the largest child view. If you use a Frame Layout as Fragment Container you can ensure that you always have the space available to accommodate the largest fragment layout.

In some cases you may need to have more than 1 fragment on screen simultaneously in that case you should prefer Relative or Linear Layout.

like image 29
Sumit Dhaniya Avatar answered Sep 21 '22 06:09

Sumit Dhaniya