Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CardView.setRadius() is not working when assigned programmatically

Tags:

java

android

So in my program, I want to generate CardViews dynamically on a predefined Layout that I intend to place inside a LinearLayout with horizontal orientation, which is inside a horizontal ScrollView. Everything in the code works fine except:

cv.setRadius(Tools.convertDpToPx(context,5));

[cv is a CardView Object]

[Tools.convertDpToPx(context,float) resides in Tools as static function and returns translated values in Pixels from DP]

Tried getting cv.getRadius() to check if my values are getting assigned, and they are.

Does anyone have an idea why the setRadius() is not working?

IMPLEMENTATION OF CODE

CardView cv = new CardView(context);
// Set external card view wrapper(cv) properties
CardView.LayoutParams cvlp=new CardView.LayoutParams(Tools.convertDpToPx(context,155),Tools.convertDpToPx(context,200));
cvlp.leftMargin=Tools.convertDpToPx(context,10);
cv.setLayoutParams(cvlp);
cv.setBackground(new ColorDrawable(Color.parseColor("#002038")));
cv.setPreventCornerOverlap(false);
cv.setRadius(Tools.convertDpToPx(context,5));
//And more elements added to Card View Layout
cv.setId(View.generateViewId());
like image 358
Soumyadeep Ghosh Avatar asked Sep 05 '25 03:09

Soumyadeep Ghosh


1 Answers

Adding a Background or Background Color to a CardView will remove Rounded Corners.

like image 199
Soumyadeep Ghosh Avatar answered Sep 07 '25 23:09

Soumyadeep Ghosh