【移动应用开发技术】怎么在Android中使用FontMetrics对象计算坐标_第1页
【移动应用开发技术】怎么在Android中使用FontMetrics对象计算坐标_第2页
【移动应用开发技术】怎么在Android中使用FontMetrics对象计算坐标_第3页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

【移动应用开发技术】怎么在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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论