-1

I do not know how to name such effect but here is what I wan't to achieve. And I wonder if it's possible to do that just with xml layouts.

I have 2 text views. Text_View_A Text_View_B

Text_View_A has ellipsize enabled.

I want that Text_View_B would always be to the right of Text_View_A enter image description here

but also so that Text_View_A would be to the left of Text_View_B and ellipsize would kick in if there is not enough room for it.
enter image description here

Is it possible to achieve that with just layouting? Or do I have to do manual calculations?

Martynas Jurkus
  • 9,231
  • 13
  • 59
  • 101

2 Answers2

0

You can use relative layout and set Text_View_B to parentRight true and set Text_View_A toLeft of Text_View_B.

    <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content">
    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Text_View_B"
        android:layout_alignParentRight="true" />

    <TextView android:layout_width="match_parent" 
        android:layout_height="wrap_content"
        android:id="@+id/Text_View_A"
        android:layout_toLeftOf="@id/Text_View_B" />
</RelativeLayout>
Harshid
  • 5,701
  • 4
  • 37
  • 50
vipul mittal
  • 17,343
  • 3
  • 41
  • 44
0
<LinearLayout>
      <TextView android:id="@+id/textview_1" android:weight="7" />
      <TextView android:weight="3"/>
</LinearLayout>

textview_1.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
textview_1.setMaxWidth(textview_1.getMeasuredWidth());

try this.

venciallee
  • 775
  • 4
  • 19