Advantage and disadvantage of CardView

前提是你 提交于 2019-12-03 09:49:26

Advantage of Cardview is definitely its default implementation of the shadow and the rounded corners, in simple words Cardview is just a FrameLayout with shadow and rounded corners. You can do almost the same stuff with a Cardview that you can do with a Framelayout(as Cardview extends FrameLayout). The Cardview for API>21 uses the elevation api to set the shadows whereas for below API 21 it adds a padding with grey background to create fake shadows(just similar to the custom implementation you were talking about).

Cardview is designed to hold a single child view within itself and would be very difficult to manage multiple child views without overlapping over each other as there is no support of property such as layout_below,layout_torightof etc.. to overcome this, the approach taken by developers would be to add another Relativelayout within the Cardview to manage the child views, now this would lead to more resource consumption due to nested layouts.

To handle complex layouts its recommended to use the custom views and just to use a single child view use the Cardview.

To simply put the overhead of the rounded edges and shadows: If you consider the Framelayout as a cake then the elevation is like the icing and rounded edges is like cherry topping. Its aesthetic with the icing and the topping but you have to shed additional bucks for the icing and cherry.

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