I'm a little confused about your present text file(s) and their format. I understand your required behavior. Your implementation will need to use the separation of chords and lyrics to affect the wrapping. Therefore, delineating chords and lyrics is necessary. I will focus on the logic and design rather than specific implementation of my possible solutions. Please comment with further concerns.
Problematic Format:
[----1st phrase chords----][----1st phrase lyrics----][----2nd phrase chords----][----2nd phrase lyrics----]
If this is the case, you may have trouble, since you won't be able to know where the lyrics begin when your first line of chords is full. For example, see the pseudocode below:
String textFile = //your song
while textFile has characters left
fill a line of the TextView with chords
fill the next line of the TextView with the associated lyrics
endwhile
The second line within the while-loop
can't be performed, since you don't know where the lyrics begin. You may need to manually adjust your files to be in the format of the second design, since they were probably manually spaced to fit this format (if this format).
Fixed Formats:
These formats acknowledge and fix the problem of logically separating chords and lyrics. One format:
[----1st phrase chords----]
[----1st phrase lyrics----]
[----2nd phrase chords----]
[----2nd phrase lyrics----]
where you would read each line into separate Strings, or another with two separate files:
chords.txt:
[----1st phrase chords----]
[----2nd phrase chords----]
lyrics.txt:
[----1st phrase lyrics----]
[----2nd phrase lyrics----]
I say text files, but it could be data received through a network request, etc.
Once you've split your chords and lyrics, there may be a more Android-specific solution for TextViews
, but I have two ideas for work-arounds.
The first workaround could calculate the number of characters fitting in a single line of your TextViews and split the text accordingly. I.e.:
Discover a line of the TextView holds X monospaced characters
While the chords and lyrics aren't exhausted
Fill a new TextView line with X characters of chords
Fill a new TextView with X characters of lyrics
Endwhile
Another possible work-around could use two TextViews
with double (or greater) line-spacing and placing them on-top of each other. You could have one TextView
hold chords and the other hold lyrics, with an extra line of whitespace at the top of the lyrics. Here's my attempt at an illustration:
. First TextView below Second TextView
[----1st phrase chords ----] [----Whitespace added manually ----]
[----Line-spacing whitespace----] [----1st phrase lyrics ----]
[----2nd phrase chords ----] [----Line-spacing whitespace ----]
[----Line-spacing whitespace----] [----2nd phrase lyrics ----]
Important Consideration:
You will want to use a monospaced font. This will mean all characters are the same width. Otherwise, the specific characters will affect the number fitting in each line.