Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FrameLayout vs RelativeLayout for overlays

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?

like image 972
dev Avatar asked Apr 05 '14 01:04

dev


People also ask

What's a FrameLayout When should you use FrameLayout instead of RelativeLayout?

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.

Which is better Linearlayout or RelativeLayout?

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.

Which is better ConstraintLayout and RelativeLayout?

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.

What is the difference between FrameLayout and RelativeLayout in Android?

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 ...


1 Answers

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.

like image 88
scottt Avatar answered Oct 18 '22 07:10

scottt