寻找角色的座标? [英] Finding coordinates of a character?

查看:60
本文介绍了寻找角色的座标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多行 TextView 。有没有一种方法可以将像素的x坐标获取到字符的左侧,例如第三个角色?在我的情况下,它将始终是第三个字符,但是一般的解决方案会更好。

I have a multi-line TextView. Is there a way to get the x coordinate of the pixel to the left of a character e.g. the 3rd character? In my case it will always be the 3rd character, but a general solution would be nicer.

我使用以下命令将像素的y坐标恰好位于字符上方:

I have the y coordinate of the pixel just above the character using:

Layout textViewLay = mTextView.getLayout();
int posY = textViewLay.getLineTop(0);

但是x坐标让我很困惑。有任何想法吗?我可能缺少一些非常简单的东西。

but the x coordinate has me stumped. Any ideas? I'm probably missing something really simple.

推荐答案

尝试使用此代码:

Rect bounds = new Rect();
Paint tpaint = textView.getPaint();
tpaint.getTextBounds(text,0,2,bounds);
int height = bounds.height();
int width = bounds.width();

这篇关于寻找角色的座标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆