I have a layout where I have a two TextViews horizontally next to each other. What I am trying to achieve is a view where the second TextView is aligned to the right of the first, but if the TextView in the first gets too long it will truncate when the right edge of the right TextView hits the edge of the container. The text is set dynamically and can be of varying lengths.
A diagram of what I am trying to achieve is below (yellow = container, red box = second TextView):
The code I have at the moment is below:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:ellipsize="end"
android:singleLine="true"
android:textColor="@android:color/white"
android:textIsSelectable="false"
android:text="Test"
android:textSize="18sp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@id/textView1"
android:background="@drawable/textView2Background"
android:paddingBottom="2dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:paddingTop="2dp"
android:text="TextView2"
android:textColor="@android:color/white"
android:textSize="15sp" />
</RelativeLayout>
However, the first TextView is only truncating when it hits the end of the container, at which point the second TextView has been pushed outside it and is no longer visible.
Thanks