Change padding of a CardView programmatically

+2 votes
asked May 16, 2016 by yoann-hercouet

I came across this weird problem with the CardView from the compatibility library, I need to change dynamically the padding of a CardView but it just seems not implemented...

Here is what I found in the parent CardView class:

public void setPadding(int left, int top, int right, int bottom) { // NO OP

I don't know the reason why but they just skipped this on the card views.

Is there any alternative to set the padding dynamically?

1 Answer

+1 vote
answered Nov 29 by karthiksrndrn

Instead of changing the padding of CardView try putting the contents of the CardView inside a single root layout - a FramLayout or a RelativeLayout or something.

Then change the padding of this root layout.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.