I'm trying to create a layout with two TextViews next to each other. The first TextView has a variable length and is single-lined. The second TextView contains a fixed label and should not be ellipsized.
The second label has to be right next to the first one.
Here are two examples of what I'm trying to accomplish:

This is what I've achieved so far:

With this layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/my_bg"
android:padding="16dp"
tools:layout_height="60dp">
<TextView
android:layout_centerVertical="true"
android:id="@+id/tv_street"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/tv_updated"
android:textSize="17sp"
android:singleLine="true"
android:ellipsize="end"
android:layout_marginLeft="16dp"
tools:text="This label is short"/>
<TextView
android:id="@id/tv_updated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="@string/updated"
android:textAllCaps="true"
android:textColor="@color/red"
android:textStyle="bold"/>
</RelativeLayout>
The remaining problem is that the container gets a width that matches its parent while it should be wrap_content.
Are there any other ways to fix this?
you better use linearlayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="16dp"
android:orientation="horizontal"
android:gravity="center_vertical"
tools:layout_height="60dp">
<TextView
android:id="@+id/tv_street"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17sp"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="end"
android:layout_marginLeft="16dp"
tools:text="This label is short"/>
<TextView
android:id="@id/tv_updated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="UPDATED"
android:textAllCaps="true"
android:textColor="@color/red"
android:textStyle="bold"/>
</LinearLayout>
edited: here the prove

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With