FrameLayout vs RelativeLayout for overlays

大兔子大兔子 提交于 2019-11-28 19:28:47

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/22875453/framelayout-vs-relativelayout-for-overlays

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!