android drawtext 如何使文字居中
来源:互联网 发布:大淘客联盟cms怎么申请 编辑:程序博客网 时间:2024/05/21 12:51
水平居中很简单,设置Paint.Align.CENTER 属性即可。mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);mTextPaint.setStrokeWidth(3);mTextPaint.setTextSize(80);mTextPaint.setTextAlign(Paint.Align.CENTER);mTextPaint.setColor(0xff00ff00);
垂直居中有点难度,需要计算一下:private Paint.FontMetricsInt fmi;fmi = mTextPaint.getFontMetricsInt();float fontheight = fmi.bottom - fmi.top;Log.e("&&&&&", "fmi.top =" + fmi.top + "::bottom=" + fmi.bottom);Log.e("&&&&&", "fmi.ascent =" + fmi.ascent + "::fmi.descent=" + fmi.descent);其中top ascent 都是负值, bottom descent 正值。综合计算公式如下(主要就是计算相对于baseline 的偏移):我是这样理解的。text的中心基于baseline偏移量 (fmi.top + fmi.bottom)/2.所以mTextCenterY = mCenterY - (fim.top + fmi.bottom)/2. 简化如下:mTextCenterY = mCenterY - fmi.top/2 - fmi.bottom/2;canvas.drawText(String.valueOf(mPercent) + "%", mCenterX, mTextCenterY, mTextPaint);text 边界介绍如下图(图示从别处摘来的)
如上图所示坐标。
0 0
- android drawtext 如何使文字居中
- ANDROID drawText实现文字居中
- android canvas drawText()文字居中
- Android Canvas drawText()文字居中
- android canvas drawText()文字居中
- android drawText时使文字居中、获取文字宽高
- Android 中Canvas.drawText实现文字居中
- Android之drawText()文字居中问题
- Android 史上最简单的实现Canvas drawText文字垂直居中
- DrawText如何使多行文字居中
- DrawText如何使多行文字居中
- DrawText如何使多行文字居中
- DrawText如何使多行文字居中
- DrawText上下左右居中输出文字
- canvas drawText文字垂直居中
- Android drawText 纵向居中
- canvas drawText 如何居中显示。
- canvas.drawText文字居中(备忘)
- 五子棋的c语言源码
- HADOOP 启动NodeManager闪退,logs信息:java.net.NoRouteToHostException: 没有到主机的路由
- poj1006 Biorhythms
- 三层架构和MVC比较的个人理解
- IOS版本更新代码——商店版本
- android drawtext 如何使文字居中
- android基础总结篇之九:Intent应用详解
- Hadoop重启,Hbase出现Master exiting的错误:org.apache.hadoop.hbase.master.HMasterCommandLine: Master exiting
- matlab在程序里%%是什么意思
- android Intent常用介绍
- Unable to execute dex: Multiple dex files define Lcom/android/volley/VolleyError;
- Kafka High Availability (下)
- 修改和重置WAMP的phpMyAdmin密码
- 在OJ上Judge Status评判出错常见系列