下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】怎么在Android中使用FontMetrics对象计算坐标
这期内容当中在下将会给大家带来有关怎么在Android中使用FontMetrics对象计算坐标,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。Canvas绘制文本时,使用FontMetrics对象,计算位置的坐标。public
static
class
FontMetrics
{
/**
*
The
maximum
distance
above
the
baseline
for
the
tallest
glyph
in
*
the
font
at
a
given
text
size.
*/
public
float
top;
/**
*
The
recommended
distance
above
the
baseline
for
singled
spaced
text.
*/
public
float
ascent;
/**
*
The
recommended
distance
below
the
baseline
for
singled
spaced
text.
*/
public
float
descent;
/**
*
The
maximum
distance
below
the
baseline
for
the
lowest
glyph
in
*
the
font
at
a
given
text
size.
*/
public
float
bottom;
/**
*
The
recommended
additional
space
to
add
between
lines
of
text.
*/
public
float
leading;
}它的各基准线可以参考下图:上图其实是通过代码画出来的,具体代码如下:/**
绘制FontMetrics对象的各种线
*/
mPaint.reset();
mPaint.setColor(Color.WHITE);
mPaint.setTextSize(80);
//
FontMetrics对象
FontMetrics
fontMetrics
=
mPaint.getFontMetrics();
String
text
=
"abcdefg";
//
计算每一个坐标
float
textWidth
=
mPaint.measureText(text);
float
baseX
=
30;
float
baseY
=
700;
float
topY
=
baseY
+
fontMetrics.top;
float
ascentY
=
baseY
+
fontMetrics.ascent;
float
descentY
=
baseY
+
fontMetrics.descent;
float
bottomY
=
baseY
+
fontMetrics.bottom;
//
绘制文本
canvas.drawText(text,
baseX,
baseY,
mPaint);
//
BaseLine描画
mPaint.setColor(Color.RED);
canvas.drawLine(baseX,
baseY,
baseX
+
textWidth,
baseY,
mPaint);
mPaint.setTextSize(20);
canvas.drawText("base",
baseX
+
textWidth,
baseY,
mPaint);
//
Base描画
canvas.drawCircle(baseX,
baseY,
5,
mPaint);
//
TopLine描画
mPaint.setColor(Color.LTGRAY);
canvas.drawLine(baseX,
topY,
baseX
+
textWidth,
topY,
mPaint);
canvas.drawText("top",
baseX
+
textWidth,
topY,
mPaint);
//
AscentLine描画
mPaint.setColor(Color.GREEN);
canvas.drawLine(baseX,
ascentY,
baseX
+
textWidth,
ascentY,
mPaint);
canvas.drawText("ascent",
baseX
+
textWidth,
ascentY
+
10,
mPaint);
//
DescentLine描画
mPaint.setColor(Color.YELLOW);
canvas.drawLine(baseX,
descentY,
baseX
+
textWidth,
descentY,
mPaint);
canvas.drawText("descent",
baseX
+
textWidth,
descentY,
mPaint);
//
ButtomLine描画
mPaint.setColor(Color.MAGENTA);
canvas.drawLine(baseX,
bottomY,
baseX
+
textWidth,
bottomY,
mPaint);
canvas.drawText("buttom",
baseX
+
textWidth,
bottomY
+
10,
mPaint);相信通过以上程序,能够很好的理解topLine,buttomLine,baseLine,ascentLine,descentLine。另外:Paint类有两个方法/**
*
Return
the
distance
above
(negative)
the
baseline
(ascent)
based
on
the
*
current
typeface
and
text
size.
*
*
@return
the
distance
above
(negative)
the
baseline
(ascent)
based
on
the
*
current
typeface
and
text
size.
*/
public
native
float
ascent();
/**
*
Return
the
distance
below
(positive)
the
baseline
(descent)
based
on
the
*
current
typeface
and
text
size.
*
*
@return
the
distance
below
(positive)
the
baseline
(descent)
based
on
*
the
current
typeface
and
text
size.
*/
public
native
float
descent();ascent():thedistanceabovethebaseline(baseline以上的height)descent():thedistancebelowthebaseline(baseli
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 《负数》选择题50道专项练习【综合卷】
- 《智慧广角-植树问题》(教案)-2023-2024学年人教版三年级数学下册
- 部编版道德与法治小学六年级下册《期末测试卷》加答案(基础题)
- 六年级下册数学期末考试真题汇编-判断题100道含答案(黄金题型)
- 六年级下学期数学基础知识《填空题》专项练习带答案(考试直接用)
- 人教版六年级上册数学期中考试试卷及解析答案
- 湘艺版音乐 八年级下册 第七单元 中国人民解放军进行曲 教案
- 语文园地一 (第二课时)(教学设计)2023-2024学年统编版语文五年级下册
- 人教版数学六年级上册期中测试卷及参考答案(b卷)
- 教科版科学四年级下册第三单元《岩石与土壤》测试卷附答案【基础题】
- 管理会计项目六短期经营决策分析
- 四年级上册美术教案-第17课 手绘导游图 ▏人美版(北京)
- 防溺水安全教育情景剧剧本
- 水利水电工程质量检测讲义ppt(103页)
- DB61∕T 5018-2022 民用建筑机电安装工程标识标准
- 河南中医学院第二附属医院进修人员申请及鉴定表
- 三菱变频器fr a700使用手册
- 消防水操作规程
- 新加坡教育培训之行
- 外贸服装尺寸术语集合
- 计价格(2002)10号文
评论
0/150
提交评论