In my case, I was using Relative Layout
for a emptyString
After struggling on this for an hour. Only this worked for me:
android:layout_toRightOf="@id/welcome"
android:layout_toEndOf="@id/welcome"
android:layout_alignBaseline="@id/welcome"
layout_toRightOf
or layout_toEndOf
both works, but to support it better, I used both.
To make it more clear:
This was what I was trying to do:
And this was the emulator's output
Layout:
<TextView
android:id="@+id/welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="Welcome "
android:textSize="16sp" />
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@id/welcome"
android:layout_toRightOf="@id/welcome"
android:text="@string/emptyString"
android:textSize="16sp" />
Notice that:
android:layout_width="wrap_content"
worksGravity
is not used