Clip For GradientDrawable.setCornerRadii not working

I'm trying to create a view with custom radius but facing a problem when using GradientDrawable.setCornerRadii...
Line If i use Below code the view clips all the child view inside it

public void SetCornerRadius(View v,int Radius){
        GradientDrawable shape = new GradientDrawable();
        shape.setShape(GradientDrawable.RECTANGLE);
        shape.setCornerRadius((int)Px2Dp(Radius));
        v.setBackground(shape);
        v.setOutlineProvider(ViewOutlineProvider.BACKGROUND);
        v.setClipToOutline(true);
    }

But if i use Below code for different corner radius then Clipping is not working as expected as child view goes outside parent view

public void SetDifferentCornerRadius(View v,int TopLeftRadius,int TopRightRadius,int BottomLeftRadius,int BottomRightRadius,String backgroundColor){
        GradientDrawable shape = new GradientDrawable();
        ViewGroup vg = (ViewGroup)v;
        shape.setShape(GradientDrawable.RECTANGLE);
        shape.setColor(Color.parseColor(backgroundColor));
        shape.setCornerRadii(new float[] { (int)Px2Dp(TopLeftRadius),(int)Px2Dp(TopLeftRadius),(int)Px2Dp(TopRightRadius),(int)Px2Dp(TopRightRadius),(int)Px2Dp(BottomRightRadius),(int)Px2Dp(BottomRightRadius),(int)Px2Dp(BottomLeftRadius),(int)Px2Dp(BottomLeftRadius)});
        v.setBackground(shape);
        v.setOutlineProvider(ViewOutlineProvider.BACKGROUND);
        v.setClipToOutline(true);

    }


Read more here: https://stackoverflow.com/questions/64942425/clip-for-gradientdrawable-setcornerradii-not-working

Content Attribution

This content was originally published by NikzDreamer at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: