Android CardView remove padding

UDPATE

Well, seems there is a much easier way to do it, without guessing the padding and all:

card_view:cardPreventCornerOverlap="false"

or using java:

cardView.setPreventCornerOverlap(false)

You can read all about it here.

ORIGINAL ANSWER

It is an intentional padding to avoid content from bleeding off the rounded corner of the card in pre lollipop versions (since clipping is not available). If you want to get rid of it all together you may use a negative padding in pre-lollipop versions for the contentPadding attribute of the CardView such as:

card_view:contentPadding="-8dp"

or using java:

int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
cardView.setContentPadding(-padding,-padding,-padding,-padding);

I’m not particularly sure which value will work seamlessly, you’ll need to experiment and see for yourself.

Leave a Comment