I have problems getting two Textviews to behave the way I want.
I want one on the left side, the other one on the right side. I fairly simply achieved this with a horizontal linear layout. Both of them should only use half of the horizontal space (“stay on their side”) and expand vertically if the string is too long.
However, if one or both of the text views contain a very long string, I get weird results depending on how I set weight.
E.g. if I set weight to Left=1, Right=1 everything works fine if both strings are short or both strings are long. If they differ, however, the short one is shrinked to only show on character each line. Using 0/0 weight, the shorter TextView just completely vanishes.
I can get it to work if I set the short string text view to “0” and the long one to “1” or higher, but that only covers one case.
I also experimented with TableLayout and RelativeLayout but nothing worked.
Kind regards,
jellyfish
Edit:
Solved it by putting the TextViews into vertical LinearLayouts inside the horizontal Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_gravity="right">
</TextView>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_gravity="right">
</TextView>
</LinearLayout>
</LinearLayout>
Seems a bit oversized to me, though… but apparently there’s no other solution?
This works fine with me if I set one letter string to the first textView and very long string to the second textView