FrameLayout vs. RelativeLayout for Overlays

I need to implement an overlay (translucent) screen for my application, something similar to the Showcase view

My guess was to use FrameLayout for this utility, as it is used to stack elements on top of each other. But I was surprised to see that the above library uses RelativeLayout .

My question is when to use FrameLayout , and if not in such cases? What are the disadvantages if I follow the FrameLayout path?

+56
android android-relativelayout android-framelayout
Apr 05 '14 at 1:16
source share
1 answer

The general rule when choosing layouts is to choose a combination that results in the least number of nested layout types.

Depending on your question, RelativeLayout is bigger and more efficient than the much simpler FrameLayout. So for simple layouts, the latter is probably more efficient. But if using RelativeLayout and the added positioning options allows you to implement a graphical interface in fewer layout types, then this is probably the best choice.

Here's a page that discusses some of the trade-offs and demonstrates some useful tools you can use when developing layouts. This is mainly about RelativeLayout and LinearLayout, but is also relevant to your choice between RelativeLayout and Framelayout. Just remember that FrameLayout is an even simpler layout.

Edit (2017): For even more complex layouts, you can avoid nested layouts using ConstraintLayout.

+55
Apr 05 '14 at 1:42 on
source share
β€” -



All Articles