0

Assuming that I have a TextView with text inside. Is it possible to get from that TextView some word's coordinates on the screen?

Seraphis
  • 1,026
  • 2
  • 14
  • 30

2 Answers2

1

Here goes

TextView tv;
int[] coordinates = new int[2];

tv.getLocationOnScreen(coordinates);

Log.v("Coordinates of my TextView are: ", "Left(X) = "+coordinates[0]+" and Top(Y) = "+coordinates[1]);

Hope it helped))) Actually, it works for any view - not only a TV.

UnknownJoe
  • 599
  • 5
  • 14
  • 30
  • I wanted a particular word from that TV :-) But this answer could be a good start. I have to get letter's width in px and try to calculate distance from start of View. The problem is when there are more than one rows of text. – Seraphis May 02 '12 at 15:52
  • If I get what you mean try to use – UnknownJoe May 02 '12 at 19:08
  • No, I don't want to make ellipsize :-) Just to replace part of text with image ;-) – Seraphis May 02 '12 at 20:29
1

I had the same problem and I have resolved it. You have to use clickableSpan inside your TextView. See my post for more details, and tell me if you have any problem :)

Community
  • 1
  • 1
Sébastien BATEZAT
  • 2,353
  • 26
  • 42