World Tech

Unable to get exact circle shape when using card view –

Development issue/problem:

I use the map view for the floating action button in Android Material Design. I use the following code to get a circle.

I set the corner radius to half the width. But I still can’t get a circular shape.

How can I solve this problem?

Solution 1:

To get a circular shape with the card view, you can set the shape property, android:shape=ring.
app:cardCornerRadius should be set to half the width or height of the child’s view.

Solution 2:

I solved the problem. Android now offers a material design library with a floating action button. It is not necessary to adjust the map view for the floating action button.

Adding a design library for classification dependencies

Compile 23.1.1.

You can find more information by clicking on the following link

Solution 3:

To achieve a perfect circular shape with the postcard, the radius of the angle should be half the width or height (assuming it is a square). I also noticed that you are using the card_view settings, don’t do that.

Solution 4:


shape = ring
use the same layout_height and layout_weight.


app:cardCornerRadius= half the height_length or weight_disposition.


Solution no. 5:

I found a simple solution with Drawable, and it’s fantastic!

You can get a drawing here

Solution no. 6:

I tried your code and found that the maps are less round when you increase the height value. Try setting it to zero and it will at least look better.

card_view: cardElevation=0dp ;

But maybe a better option would be to use the floating action button for the round button.

Solution no. 7:

Solution no. 8:

Yes, I did it by reducing half of CardCornerRadius to his eyesight.

Solution no. 9:


ImageView imageView = (ImageView) findViewById( ;
Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.rose) ;

} else {
RoundCornersDrawable round = new RoundCornersDrawable(mBitmap,
getResources().getDimension(R.dimen.cardview_default_radius), 0); /or your own radius.

CardView cardView = (CardView) findViewById(;
cardView.setPreventCornerOverlap(false); // This is very important.


The RoundCornersDrawable public class extends Drawable {

final private float mCornerRadius;
final private RectF mRect = new RectF();
//private final RectF mRectBottomR = new RectF();
//private final RectF mRectBottomL = new RectF();
final private BitmapShader mBitmapShader;
final private Paint mPaint;
final private int mMargin ;

public RoundCornersDrawable(Bitmap, floating angleRadius, int margin) {
mCornerRadius = cornerRadius ;

mBitmapShader = new BitmapShader (bitmap,
Shader.TileMode.CLAMP, Shader.TileMode.CLAMP) ;

mPaint = new Paint() ;
mPaint.setAntiAlias(true) ;
mPaint.setShader(mBitmapShader) ;

mMargin = margin;

@Overrideprotected void onBoundsChange(RectB9 super.onBoundsChange(bounds);mRect.set(mMargin, mMargin, limits.width() – mMargin, limits.height() – mMargin);//mRectBottomR.set( (connections.Width() -mMargin) / 2, (limitss.Height() -mMargin)/ 2,bounds.Width() – mMargin, limits.Height() – mMargin);// mRectBottomL.set( 0, (limitss.Height() -mMargin) / 2, (limitss.Width() -mMargin)/ 2, limitss.Height() – mMargin);}

public void draw(Canvas) {
canvas.drawRoundRect(mRect, mCornerRadius, mPaint);
//canvas.drawRect(mRectBottomR, mPaint); //only the bottom right corner without rounding
//canvas.drawRect(mRectBottomL, mPaint); //only the bottom left corner without rounding


public int getOpacity() {
return PixelFormat.TRANSLUCENT;

public void setAlpha(int alpha) {

public void setColorFilter(ColorFilter cf) {


Solution no. 10:

Start by importing the DrawbleToolBox library into your project.
You can use this library to create dynamic drawings.

To form a circle from your map view, the radius must be half the height/width.

int radius = cardView.getHeight()/2 ;
Drawable DrawableBuilder()

.topRightRadius(radius) // in pixels
// other places
.build() ;

Holder.cardView.setBackground(image) ;

If you are using the map view in the Recycle View, getting the width of the map view does not work
because it has not yet been created. So you need to do the following

holder.cardView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener()
public boolean onPreDraw()
//codes here.

Good luck!

Related Tags:

 corner smoothing csshow to clip a circle shape into a buttonfigma bend toolfigma arc toolsquircleshow can we create a card in figma quicklycardusecompatpaddingandroid-cardview overlapandroid-cardview shadow top onlycardusecompatpadding marginandroid-cardview padding between cardsandroid cardview shadow clippedcircular imageview android picassocircular imageview with shadow androidhow to fit image in circle in androidrounded corner imageview in android examplecircular imageview android without libraryandroid circle imageview programmaticallyhow to rotate text in pages tablehow to mirror text in pagesrotate image in pages ipadwhere is the arrange tab in pagesturn image in pageshow to rotate an image in pages on iphone

Related posts
World Tech

How to Fix api-ms-win-crt-runtime-l1-1-0.dll Missing Error? [Solved]

World Tech

Amateur Radio Keeps Connected during Coronavirus Lockdowns