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.
CardView is a new widget in Android that can be used to display any sort of data by providing a rounded corner layout along with a specific elevation. CardView is the view that can display views on top of each other. The main usage of CardView is that it helps to give a rich feel and look to the UI design.
Customized CardView First, add a CardView dependency to the application-level build. gradle file. Then create a drawable background for the cards. For that, create a new drawable resource file inside the drawable folder.
A card component only has a single slot. Cards can contain icons, images or labels, are customizable. By default, cards are rectangular with rounded corners and a gradient background.
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.
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