Finding coordinates of a character?

断了今生、忘了曾经 提交于 2019-12-06 10:37:31

问题


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.

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

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

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


回答1:


Try to use this code:

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


来源:https://stackoverflow.com/questions/20696265/finding-coordinates-of-a-character

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!