IconView.java 文件源码

java
阅读 91 收藏 0 点赞 0 评论 0

项目:betterHotels 作者:
@Override
protected void onDraw(Canvas canvas){
    Bitmap bitmap = ViewUtils.drawableToBitmap(icon);
    bitmap = Bitmap.createScaledBitmap(bitmap, currentSize, currentSize, false);
    canvas.drawBitmap(bitmap, 0, 0, new Paint());
    if(showText || (showTextWhenLarge && mode == Mode.LARGE)){
        String text = getText();
        RectF rect = new RectF();
        int textHeight = ViewUtils.getTextHeight(text, textPaint);
        int textWidth = ViewUtils.getTextWidth(text, textPaint);
        rect.left = availableWidth - ((textWidth / 2) + textSize / 2);
        rect.right = rect.left + textWidth + (textSize / 2);
        if(3 * textHeight < availableHeight){
            rect.top = 3 * textHeight;
        }else if(2 * textHeight < availableHeight){
            rect.top = 2 * textHeight;
        }else{
            rect.top = 0;
        }
        rect.bottom = rect.top +  textHeight + textSize;
        //Draw the text background
        canvas.drawRect(rect, textBackgroundPaint);
        //Draw the text
        canvas.drawText(text, rect.left + textSize / 2, rect.top + textSize / 2, textPaint);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号