Make one word always superior to another in a TextView
I
have an app that is an app that collects Christian songs for youth and now I want to add chords. So, let’s say I have the following line in the .txt file:
D G D
Strange grace! What a sweet sound
This
always happens when the lines don’t fit the screen :
D
GD
Strange Grace!
The sound is so sweet
I hope this happens:
D
Strange Grace!
GD
The sound is so sweet!
Sorry for not making it clear, I really hope this makes sense. I’ve seen other apps do this, but I don’t know how.
Edit:
My song is structured as follows:
[chord of phrase].
[phrase]
Solution
Matt offers a great explanation of how your data should be structured. I’ll just add the implementation details.
Suppose the format of the input data is as follows:
[Chord Name]
[phrase for chords].
You can use horizontal RecyclerView
to display data. The layout of each item looks like
<LinearLayout
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tv_chord_name"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/tv_phrase"/>
</LinearLayout>
I’ve only added a few properties to show the structure. You can use layout_gravity="center_horizontal"
for the first TextView to center the chord name with the lyrics.
The way it works is to set the width of the LinearLayout
to wrap_content
, which effectively means that it will be the same length as the longest child of the second TextView in your case.
Now layout_gravity="center_horizontal"
will automatically center the first TextView
based on the length of the LinearLayout
, which is exactly what you need. So there is no need to add spaces to align the content