android – Advantage and disadvantage of CardView-ThrowExceptions

Exception or error:

What are the advantages and drawbacks of CardView, other than the shadow or elevation, what is the benefit in performance and looks? What is done using CardView can also be done using a combination of other layouts.

How to solve:

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.

Leave a Reply

Your email address will not be published. Required fields are marked *