Mario Rossi
Mario Rossi

Reputation: 127

Top rounded gradient drawable

i need to create a GradientDrawable object with only the top rounded corners.

Actually i'm using this method:

public static GradientDrawable generateGradientBackground(String topColor, String bottomColor) {
    int[] colors = {Color.parseColor(topColor), Color.parseColor(bottomColor)};

    //create a new gradient color
    GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.BL_TR, colors);
    gd.setShape(GradientDrawable.RECTANGLE);
    gd.setCornerRadius(30f);

    return gd;
}

This way, all corners are rounded. I can't find a way to set the radius of only top corners. Ay ideas?

I know similar question have been asked, but no solutions seems good in my case.

Thanks

Upvotes: 2

Views: 879

Answers (1)

karan
karan

Reputation: 8853

you can use setCornerRadii (float[] radii)

You can supply radii for each of the 4 corners. For each corner, the array contains 2 values, [X_radius, Y_radius]. The corners are ordered top-left, top-right, bottom-right, bottom-left.

gd.setCornerRadii(new float[] { 8, 8, 8, 8, 0, 0, 0, 0 });

Upvotes: 3

Related Questions