DotWidget.java 文件源码

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

项目:FriendCircle 作者:
@Override
protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
    super.onDraw(shape, canvas, paint);
    if (!TextUtils.isEmpty(text)) {

        Rect r = getBounds();
        if (dotTextSize == 0) {
            dotTextSize = (int) (r.width() * 0.5);
            textPaint.setTextSize(dotTextSize);
        }
        //保证文字居中
        Paint.FontMetricsInt fontMetrics = textPaint.getFontMetricsInt();
        int baseline = r.top + (r.bottom - r.top - fontMetrics.bottom + fontMetrics.top) / 2 - fontMetrics.top;
        textPaint.setTextAlign(Paint.Align.CENTER);
        canvas.drawText(text, r.centerX(), baseline, textPaint);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号