JoanZapata / android-iconify

Android integration of multiple icon providers such as FontAwesome, Entypo, Typicons,...
http://joanzapata.com/android-iconify
Other
3.93k stars 526 forks source link

Bounds changed before draw cause rendering issue #80

Closed wizwally closed 8 years ago

wizwally commented 9 years ago

Using the IconDrawable in a LayerDrawable could cause an issue in icon rendering. I experienced that bounds has been changed before the draw method is called causing an override of the size set earlier; maybe is better to set text height from the size specified or if equals to -1 to the current bounds height.

I suggest this draw method that sizes correctly the icon if bounds has been changed and center the icon. Maybe it would be useful to set a vertical/horizantal offset/padding of the icon.

@Override
public void draw(Canvas canvas) {
    paint.setTextSize((this.size == -1) ? getBounds().height() : this.size);
    Rect textBounds = new Rect();
    String textValue = valueOf(icon.character);
    paint.getTextBounds(textValue, 0, 1, textBounds);
    float xOrigin = getBounds().left + (getBounds().width() / 2f);
    float yOrigin = getBounds().top + (getBounds().height() / 2f) + (textBounds.height() / 2f);
    canvas.drawText(textValue, xOrigin , yOrigin, paint);
 }
JoanZapata commented 9 years ago

Sorry for the delay, do you have an example code to show what the problem is using LayerDrawable, so that I can test your code in the right conditions?

JoanZapata commented 8 years ago

Closed due to inactivity. Feel free to reopen and provide additional info.