Currently I'm using paintObject.measureText(textCopy.substring(0,i))
while iterating through a copy of the TextView's text. For example, measureText("abc".substring(0,1))
will give me the relative x coordinates of 'b'. The y coordinate I get from layout.getLineTop()
. This is working but not accurate for x coordinates for non-monospaced fonts. I can calibrate a little, but on each device it works differently.
The best solution I can think of is to overwrite the class that is responsible for drawing the TextView on the screen and, hopefully, get the coordinates of each character drawn to screen.
Does anyone know what class I need to overwrite to accomplish this? Or maybe some other creative solution?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…