Finding the coordinates of a letter placed in a TextView

I have a text view that contains long text that covers half the screen,

In this text view, I have two words in a different position, above which I have to place an empty layout that will give it a glass effect.

I can do this by placing a text image in a frame and placing a layout above it.

The problem is how to get the coordinates of words, since the text can be placed in different positions on different devices.

enter image description here

I want to place the layout in a place marked in white. Can someone please help Thanks.

+5
source share
3 answers

It will be useful for you.

public void getLocationOnScreen (int[] location)
    Since: API Level 1

Computes the coordinates of this view on the screen. The argument must be an
array of two integers. After the method returns, the array contains the x and y
location in that order.

Parameters
   location   an array of two integers in which to hold the coordinates

, , .

+3

, TextView - TextView. .... , ( , !

+1

What you really want here is backgroundspan:

span = new BackgroundColorSpan(Color.WHITE);
text.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
-1
source

All Articles