I need to implement an overlay (translucent) screen for my app, something similar to Showcase View
My guess was to use FrameLayout
for this usecase, because it is used to stack items on top of each other. But I was surprised to see that the above library uses RelativeLayout
.
My question is when to use FrameLayout
then, if not in cases like this? What are the disadvantages if I go the FrameLayout
way?
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.
Relativelayout is more effective than Linearlayout. From here: It is a common misconception that using the basic layout structures leads to the most efficient layouts. However, each widget and layout you add to your application requires initialization, layout, and drawing.
ConstraintLayout has flat view hierarchy unlike other layouts, so does a better performance than relative layout. Yes, this is the biggest advantage of Constraint Layout, the only single layout can handle your UI.
RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets. TableLayout : is a view that groups its child views into rows and columns. FrameLayout : is a placeholder on screen that is used to display a single ...
A common rule of thumb when choosing layouts is to select the combination that results in the smallest number of nested layout views.
Specific to your question, RelativeLayout is larger and more capable than the much simpler FrameLayout. So for simple layouts, the latter is probably more efficient. But if using RelativeLayout and it's added positioning options allows you to implement your GUI in a smaller number of layout views, then that would likely be a better choice.
Here's a page that discusses some trade-offs and demonstrates some helpful tools to use when designing your layouts. It mostly talks about RelativeLayout and LinearLayout, but is also apropos to your choice between RelativeLayout and Framelayout. Just keep in mind that FrameLayout is an even simpler layout.
Edit (2017): For even more complicated layouts, you may be able to avoid nested layouts by using ConstraintLayout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With