3

It is easy to place one TextView at right of another TextView but when width on base TextView more than screen size right TextView became not visible.

My XML layout:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:id="@+id/messages"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:lines="1"
    android:text="Messages" />

<TextView
    android:id="@+id/counter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:background="@drawable/bg_white_r30p0pl10"
    android:drawableRight="@drawable/arrow_orange"
    android:text="800" />

</LinearLayout>

How to make right TextView screen even if base TextView width is huge?

UPD:

In other words I need:

If first TextView is short:

   |[ShotrTextView][TextView]      |

If first TextView is long:

   |[LooooooongTextVi...][TextView]|
Nik
  • 7,114
  • 8
  • 51
  • 75
  • Take `RelativeLayout` and use `LayoutAlignParentRight`. – Mohammed Azharuddin Shaikh Sep 19 '12 at 07:27
  • RelativeLayout with LayoutAlignParentRight works like my layout! I need when message is short, right TextView must places at right bound of message, when message is long TextView must places at right screen border! – Nik Sep 19 '12 at 07:38

4 Answers4

4

The solution is TableLayout usage with shrinkColumns = 0

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="0" >

<TableRow
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >




    <TextView
        android:id="@+id/messages"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:lines="1"
        android:text="Messages" />

    <TextView
        android:id="@+id/counter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:background="@drawable/bg_white_r30p0pl10"
        android:drawableRight="@drawable/arrow_orange"
        android:text="800" />


</TableRow>

</TableLayout>
Nik
  • 7,114
  • 8
  • 51
  • 75
1

Try this

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:ellipsize="end"
        android:inputType="text"
        android:text="" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_weight="0"
        android:inputType="text"
        android:text="12345" />

</LinearLayout>
Asha Soman
  • 302
  • 2
  • 6
  • 18
1

Posting this as thinking line the only way to do the so...

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:singleLine="true"
                android:layout_height="wrap_content"
                android:text="Medium TextMedium TextMedium TextMedium Text"
                android:maxWidth="280dp"
                android:ellipsize="end"
                />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="HHH"
                 />

And create one dimension file like this and use it.

Community
  • 1
  • 1
MKJParekh
  • 34,073
  • 11
  • 87
  • 98
0

Check the answer in: Two TextViews side by side, only one to ellipsize?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<TextView android:id="@+id/messages" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" 
android:ellipsize="end" android:lines="1" android:text="Message" />
<TextView android:id="@+id/counter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp"
  android:layout_weight="1" android:background="@drawable/bg_white_r30p0pl10" android:drawableRight="@drawable/arrow_orange" android:text="800" /> 

</LinearLayout>
Community
  • 1
  • 1
Nermeen
  • 15,883
  • 5
  • 59
  • 72