Why is a FrameLayout used for fragments?

前端 未结 3 692
傲寒
傲寒 2020-12-05 06:14

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

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 06:54

    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

提交回复
热议问题