I've got two TextViews side-by-side. TextView1 has a varying length of text, and TextView2 always says "+#". When TextView1 gets long however, it pushes TextView2 off screen. Any ideas how to fix this? Here's my layout code:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/TextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="end"
android:textSize="13sp"/>
<TextView
android:id="@+id/TextView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="13sp"/>
</RelativeLayout>


This is actually something I've tried to solve for a while now. Unfortunately, the method others have suggested - using
layout_weightinsideLinearLayout- doesn't actually work; however, I've found a solution for you!With the above block, we use a
RelativeLayoutin order to align the firstTextViewto the left of the secondTextView. We also align the secondTextViewto the right side of the parentViewGroup. Finally, we addandroid:gravity="left"to the parentViewGroupin order to align all of theTextView's to the left.This results in both
TextView's being side by side - regardless of the firstTextView's length. If you would like the firstTextViewto have multiple lines, simply remove theandroid:ellipsize="end"tag.Hopefully this is your expected outcome!