D
D
Daniel Khaliulin2016-01-06 13:17:48
Java
Daniel Khaliulin, 2016-01-06 13:17:48

How to save the exact position of the chord above the word in Textview?

Context:
mobile application with songs and chords for singing along with the guitar.
Task:
It is necessary that the chords are indicated above the words in the text of the song. Chords should be in bold. In this case, the chords should be located above those parts of the text where the transition to this particular chord is necessary - this task is implemented by placing spaces between the chords above the text of the song itself.
As initial data, we are given lyrics (txt), where the chords are shifted to the right places with the help of spaces.
Example:
4046356b7ad44d34b42e23f5864fe716
How would you solve this problem?
UPD1: I tried to take all the text from the file into a line, add line break tags, replace spaces with and use Html.fromHtml(data) to translate everything into HTML, but for some reason the chords still shift a little (I highlighted where it moved out).

data = data.replaceAll("(\\r|\\n)", "<br>");
data = data.replace(" ", "&nbsp;&nbsp;");
tv.setText(Html.fromHtml(data));

340b0b0e53a845e297838af1696f5495

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Peter, 2016-01-06
@petermzg

I would write a custom view.
In this case, I will know exactly all the positions.

D
Dum_spiro_spero, 2016-01-08
@Dum_spiro_spero

Here's a not-so-fresh idea.
Chords change on a syllable. Highlight or underline the desired syllable - it will be clear that there should already be a new chord.
Good luck!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question