Domanda

I'm working with Android, and I've one of the weirdest error ever. This function checks wether I can or not set a bigger Font for a Paint object.

What I´m seeing here, is that EVEN when the first if sentence is TRUE... and the next one is also true, after returning the value "true"... it jumps to the last "return false;" which is absolutely imposible!

Do any of you have any idea why this could be happening? Thanks !!!

private boolean fontCanBeBigger(String text, Paint paint, Canvas canvas, int divisor){      
    if (textFitsOneLine(text, paint, canvas))
    {           
        paint.setTextSize(divisor-2);           
        if (textFitsOneLine(text, paint, canvas) && (divisor > MIN_DIVISOR))                                
        {
                paint.setTextSize(divisor+2); 
                return true;
        }
        else
        {
            paint.setTextSize(divisor+2); //set it back to previous value
            return false;
        }           
    }
    else { return false; }  
}

private boolean textFitsOneLine(String text, Paint paint, Canvas canvas)
{
    int length = paint.breakText(text, true,(float) canvas.getWidth()- MARGIN, null);       
    return length >= text.length();
}
È stato utile?

Soluzione

It's probably UI glitch of the debugger, but only a single execution path of the if statement is actually executed

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top