medyo / Fancybuttons

Icons, Borders, Radius ... for Android buttons
1.77k stars 397 forks source link

Button radius for every corner is possible? #57

Closed tsunamilx closed 8 years ago

tsunamilx commented 8 years ago

Hi

This is great button! However my project needs the button to have corner radius on only one side, is this possible?

medyo commented 8 years ago

This feature is not supported, we might add it in the coming versions.

tsunamilx commented 8 years ago

I solved by adding the following to your code, if you are interested, here is what I did:

Declare the attributes (also in attrs.xml)

    private int mRadius            = 0;
    private int mRadiusLeftTop     = 0;
    private int mRadiusLeftBottom  = 0;
    private int mRadiusRightTop    = 0;
    private int mRadiusRightBottom = 0;

Then retrieve the attributes:

        mRadius = (int) attrsArray.getDimension(
            R.styleable.FancyButtonsAttrs_fb_radius, mRadius);
        mRadiusLeftTop = (int) attrsArray.getDimension(
            R.styleable.FancyButtonsAttrs_fb_radiusLeftTop, mRadiusLeftTop);
        mRadiusLeftBottom = (int) attrsArray.getDimension(
            R.styleable.FancyButtonsAttrs_fb_radiusLeftBottom,
            mRadiusLeftBottom);
        mRadiusRightTop = (int) attrsArray.getDimension(
            R.styleable.FancyButtonsAttrs_fb_radiusRightTop, mRadiusRightTop);
        mRadiusRightBottom = (int) attrsArray.getDimension(
            R.styleable.FancyButtonsAttrs_fb_radiusRightBottom,
            mRadiusRightBottom);

Created a method to draw corners:

    private void drawCornerRadius(GradientDrawable drawable) {
        if (mRadius > 0) {
            drawable.setCornerRadius(mRadius);
        } else {
            float[] radii = new float[]{
                mRadiusLeftTop, mRadiusLeftTop, // left top xy
                mRadiusRightTop, mRadiusRightTop, // right top xy
                mRadiusRightBottom, mRadiusRightBottom, // right bottom xy
                mRadiusLeftBottom, mRadiusLeftBottom // left bottom xy
            };
            drawable.setCornerRadii(radii);
        }
    }

Replace wherever you draw the corner radius with above method.

medyo commented 8 years ago

@tsunamilx could you make a pull request for this feature ?