Actually this is what I tried to solve for a while. Unfortunately, the method others suggested - using layout_weight inside LinearLayout - doesn't actually work; however i found a solution for you!
<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="left"> <TextView android:id="@+id/TextView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/TextView2" 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:layout_alignParentRight="true" android:singleLine="true" android:textSize="13sp"/> </RelativeLayout>
In the block above, we use RelativeLayout to align the first TextView left of the second TextView . We will also align the second TextView on the right side of the parent ViewGroup . Finally, we add android:gravity="left" to the parent ViewGroup to align all TextView left.
As a result, both TextView will be side by side - regardless of the first length of the TextView . If you want the first TextView have multiple lines, just remove the android:ellipsize="end" tag.
Hope this is your expected result!
source share