I am trying to achieve a layout where two TextViews ie. tv_username and tv_date are to be aligned side by side. If the username is short the username and date should show completely and if the name is long, the username should truncate at the end and the date should show completely. Something like so :-
In any case both the TextViews shold have a max of 5dp spacing between them i.e the date should always be at the right of username with a margin of 5dp and not aligned to right in the parent. I have tried the below code, but it pushes the date Textview out of the screen with a longer username :-
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/value_3"
android:padding="@dimen/value_5"
android:paddingEnd="@dimen/value_10"
android:paddingStart="@dimen/value_10"
android:paddingTop="@dimen/value_5">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/tv_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="@integer/value_1"
android:text="Samantha George Jefferson and some more text"
android:textColor="@color/colorPrimary"
android:textSize="@dimen/size_fourteen"
android:layout_alignParentStart="true"/>
<android.support.v7.widget.AppCompatTextView
android:id="@+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/value_5"
android:layout_alignParentRight="true"
android:text="@string/friendly_date"
android:textColor="@color/colorBlack_a38"
android:textSize="@dimen/size_twelv"/>
</RelativeLayout>
Any help would be appreciated.
UPDATE
I used ConstraintLayout
but the result is the same.
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/tv_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="@integer/value_1"
android:text="Johnvfvjdfjgdkjhgjdgdjkghdjkghkjdhgdhgdgjkhjdfg"
android:textColor="@color/colorPrimary"
android:textSize="@dimen/size_fourteen"
android:layout_alignParentStart="true"/>
<android.support.v7.widget.AppCompatTextView
android:id="@+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/value_5"
android:layout_alignParentRight="true"
android:text="@string/friendly_date"
android:textColor="@color/colorBlack_a38"
app:layout_constraintLeft_toRightOf="@+id/tv_username"
android:textSize="@dimen/size_twelv"/>
</android.support.constraint.ConstraintLayout>