getTextBounds 方法作用

来源:互联网 发布:网络小胖表情包 编辑:程序博客网 时间:2024/06/07 11:48
 Rect mBounds = new Rect();
mPaint.setColor(Color.BLUE);canvas.drawRect(0, 0, getWidth(), getHeight(), mPaint);mPaint.setColor(Color.YELLOW);mPaint.setTextSize(30);String text = String.valueOf(mCount);mPaint.getTextBounds(text, 0, text.length(), mBounds);float textWidth = mBounds.width();float textHeight = mBounds.height();canvas.drawText(text, getWidth() / 2 - textWidth / 2, getHeight() / 2+ textHeight / 2, mPaint);
 getTextBounds 是将TextView 的文本放入一个矩形中, 测量TextView的高度和宽度,还有一下方法
参考:http://blog.csdn.net/it_transformers/article/details/46041899
0 0
原创粉丝点击