android-iconify
android-iconify copied to clipboard
Some icons cut off in sample app
e.g. md-access-alarm and mdi-youtube-play
Can't reproduce, can you please provide a screenshot? Which version are you using?
Iconify 2.1.0 Android 4.2.2 Fairphone 1
Here's two screenshots where I think there's some of the icons which are cut off.
That's weird, I can't see that. Thanks for the screenshots, I'll try to reproduce it with the emulator.
Seeing this with the fa-twitter icon in my app. Let me know if there is anything I can do to help debug
To fix, in class IconDrawable
change draw
method as following:
https://stackoverflow.com/questions/12166476/android-canvas-drawtext-set-font-size-from-width
@Override
public void draw(Canvas canvas) {
Rect bounds = getBounds();
int height = bounds.height();
int desiredWidth = bounds.width();
float defaultTextSize = height;
paint.setTextSize(defaultTextSize);
Rect textBounds = new Rect();
String textValue = String.valueOf(icon.character());
paint.getTextBounds(textValue, 0, 1, textBounds);
// Calculate the desired size as a proportion of our defaultTextSize.
// fix bug some Icon cut off (because some icon have width > height)
float desiredTextSize = defaultTextSize * desiredWidth/ textBounds.width();
if(desiredTextSize < defaultTextSize) {
paint.setTextSize(desiredTextSize);
paint.getTextBounds(textValue, 0, 1, textBounds);
}
int textHeight = textBounds.height();
float textBottom = bounds.top + (height - textHeight) / 2f + textHeight - textBounds.bottom;
canvas.drawText(textValue, bounds.exactCenterX(), textBottom, paint);
}