您好,欢迎来到二三娱乐。
搜索
您的当前位置:首页Android 自定义view中TextView的绘制

Android 自定义view中TextView的绘制

来源:二三娱乐
为了将TextView绘制到布局的中间

<code>
private Stirng text = "test";
private Paint.FontMetrics fm;
</code>
X轴:
<code>
//文本x
float textX = width/2-paint.measureText(text)/2;
</code>
Y轴:
<code>
//文本y
float textY = height / 2 - fm.descent + (fm.descent - fm.ascent) / 2;
</code>
这种方式获取的Y轴坐标是尽可能接近TextView的baseline的位置~~
之后drawText()
<code>
canvas.drawText( text,textX,textY,paint);
</code>

Copyright © 2019- yule263.com 版权所有 湘ICP备2023023988号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务