medyo / Fancybuttons

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

Icon drawabe is not centered by default? #58

Closed tsunamilx closed 6 years ago

tsunamilx commented 8 years ago

Hi

I found the icon drawable is not centered, even if I used gravity attribute, see screenshot (the arrow down icon on the top right): image

I have to use icon padding to do so. Am I using something wrong or this can be improved.

carmas123 commented 8 years ago

You can solve it with a simple trick :) This is Kotlin language but simple translate it in Java:

myButton.iconImageObject.lparams { gravity = Gravity.CENTER_VERTICAL }

Anyway you have iconImageObject property of FancyButton class that help you. If you use kotlin this is very simple making an extension of FancyButton class Bye

medyo commented 8 years ago

@tsunamilx could you share with us your code ?

tsunamilx commented 8 years ago

Actually I solved by adding one line to your code:

    private ImageView setupIconView() {
        if (mIconResource != null) {
            ImageView iconView = new ImageView(mContext);
            iconView.setImageDrawable(mIconResource);
            iconView.setPadding(mIconPaddingLeft, mIconPaddingTop,
                                mIconPaddingRight, mIconPaddingBottom);

            LayoutParams iconViewParams = new LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            if (mTextView != null) {
                if (mIconPosition == POSITION_TOP
                    || mIconPosition == POSITION_BOTTOM) {
                    iconViewParams.gravity = Gravity.CENTER;
                } else {
                    // Added line here
                    iconViewParams.gravity = Gravity.CENTER_VERTICAL;
                }

                iconViewParams.rightMargin = 10;
                iconViewParams.leftMargin = 10;
            } else {
                iconViewParams.gravity = Gravity.CENTER_VERTICAL;
            }
            iconView.setLayoutParams(iconViewParams);

            return iconView;
        }
        return null;
    }
monowar1993 commented 8 years ago

We need more control over icon. As I would like to set the icon on the left side of the button. Is there any way??

medyo commented 8 years ago

to set the icon to the left just use fancy:fb_iconPosition="left" If you need more control, there is a getter of the icon object getIconFontObject() or getIconImageObject ()

amatkivskiy commented 7 years ago

+1 to this issue. Can iconViewParams.gravity = Gravity.CENTER_VERTICAL be added to the library? I think it is a quite common requirement when configuring icon for the FancyButton. @medyo What do you think?

jarro commented 7 years ago

Just updated to latest version from 1.7 and icons are no longer centered vertically. Will try to resolve with top and bottom padding.

adityahas commented 6 years ago

This issue happen if the icon is vector, it's fine on PNG type.