Closed tsunamilx closed 6 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
@tsunamilx could you share with us your code ?
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;
}
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??
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 ()
+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?
Just updated to latest version from 1.7 and icons are no longer centered vertically. Will try to resolve with top and bottom padding.
This issue happen if the icon is vector, it's fine on PNG type.
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):
I have to use icon padding to do so. Am I using something wrong or this can be improved.