I'm looking for efficient way (best XML only) to align two TextView
s horizontally, smth like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/opinion_author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:maxLines="1"/>
<TextView
android:id="@+id/opinion_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
android:maxLines="1"/>
</LinearLayout>
opinion_date
will always have ~50-70dp length and must be fully visible aligned to right of opinion_author
. author may have 0-255 chars and if too much for screen then ellipsize then.
In above when author is too long view is pushing out date view. Same situation when using toRightOf
/toLeftOf
when using RelativeLayout
. Setting layout_weight=1
for author keeping date sticked to right edge of parent viewgroup even when author have only few characters, so thre is a lot of space... I'm looking for a way, which aligns date to right of author even when it is ellipsized and ends with... I have few ideas how to solve it in Java (measuring views or textpaint, but all seems not so efficient...)
Try this code: