Android Dynamic Text Drawing / Touch Detection
Solution 1:
A very broad question, and you've got a lot of work ahead, but here's the outline of one possible solution:
Create a custom view. ImageView is often a good base class to inherit.
Override the onDraw() method of the view.
Use canvas.drawText() to place your text on screen.
Use paint.getTextBounds to meausure your text. See the discussion linked below for a thorough understanding. Since you drew the text on screen, and you measured it, you know exactly where each character is.
Override the onTouch() method in your custom view and track the events you need. There are many QAs here in SO on how to do this.
For scrolling the text, use canvas.translate() using the movement you calculate in the onTouch(). Since you know how much you scrolled (translated), you know how far your characters have moved and can offset your touch detection to detect character touches.
Finally, since you now control all of the drawing and, your character positions are abstract, only having meaning when compared to a touch position, you can embellish them in any way choose.
Android Paint: .measureText() vs .getTextBounds()
Phew!
Good luck.
Post a Comment for "Android Dynamic Text Drawing / Touch Detection"