Reputation: 17
setPadding doesn't work in my code. It appears all the Cards are connected together the padding is not applied
card = new CardView(mContext);
// Set the CardView layoutParams
LayoutParams params = new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT
);
card.setLayoutParams(params);
//Set CardView Padding
card.setPadding(15,15,15,15);
// Set CardView corner radius
card.setRadius(8);
// Set cardView content padding
card.setContentPadding(15, 15, 15, 15);
Upvotes: 2
Views: 153
Reputation: 4220
Try this you can use Set cardView
content padding.
CardView card = new CardView(mContext);
// Set the CardView layoutParams
LayoutParams params = new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
);
card.setLayoutParams(params);
// Set CardView corner radius
card.setRadius(10);
// Set cardView content padding
card.setContentPadding(15, 15, 15, 15);
// Set the CardView maximum elevation
card.setMaxCardElevation(15);
// Set CardView elevation
card.setCardElevation(10);
EDIT
LayoutParams params = new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
);
params.setMargins(10, 10, 10,10);
Upvotes: 1
Reputation: 495
Use card.setContentPadding(10, 10, 10, 10);
instead of card.setPadding(15,15,15,15);
Upvotes: 1