Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ellipsize not working for textview inside table row

I am using Table layout. I have two(columns) text-views in table row. I want to apply android:ellipsize="end" at the end of the textView.

But it is not working for me, see the screen shot below. Please give me any idea, how to apply ellipsize to the textview inside a table row.

Here is the code :

<TableLayout
        android:id="@+id/linerLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_margin="10dip"
        android:background="@drawable/shape1"
        android:stretchColumns="2" >

        <TableRow
            android:id="@+id/TableRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="Product used for "
                android:textColor="@color/black_color" />

            <TextView
                android:id="@+id/productusedfor"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:ellipsize="end"
                android:minLines="1"
                android:padding="5dp"
                android:singleLine="true"
                android:text="TextView"
                android:textColor="@color/black_color" />
        </TableRow>

        <TableRow
            android:id="@+id/TableRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="Treatment for "
                android:textColor="@color/black_color" />

            <TextView
                android:id="@+id/treatementfor"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:ellipsize="end"
                android:minLines="1"
                android:padding="5dp"
                android:singleLine="true"
                android:text="TextView"
                android:textColor="@color/black_color" />
        </TableRow>

        <TableRow
            android:id="@+id/TableRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="Horse Name "
                android:textColor="@color/black_color" />

            <TextView
                android:id="@+id/horsename"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginRight="10dp"
                android:ellipsize="end"
                android:minLines="1"
                android:padding="5dp"
                android:singleLine="true"
                android:text="TextView"
                android:textColor="@color/black_color" />
        </TableRow>

        <TableRow
            android:id="@+id/TableRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="Where "
                android:textColor="@color/black_color" />

            <TextView
                android:id="@+id/location"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:ellipsize="end"
                android:minLines="1"
                android:padding="5dp"
                android:singleLine="true"
                android:text="TextView"
                android:textColor="@color/black_color" />
        </TableRow>

enter image description here

like image 512
Ganesh Avatar asked Sep 27 '12 08:09

Ganesh


2 Answers

Try this

You have to use following property. Because textview width is wrap_content so it is going outside from the tablerow. So if you use this property then it will work: android:layout_weight="1".

<TableLayout
        android:id="@+id/linerLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_margin="10dip"
        android:background="@drawable/shape1"
        android:stretchColumns="2" >

        <TableRow
            android:id="@+id/TableRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="Product used for "
                android:textColor="@color/black_color" />

            <TextView
                android:id="@+id/productusedfor"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:ellipsize="end"
                android:minLines="1"
                android:layout_weight="1"
                android:padding="5dp"
                android:singleLine="true"
                android:text="fjdsngfksngfkfngkaklmngkldfmnkldgfnskldngkldnsklnghdnklgfnkdtgfndkgfn"
                android:textColor="@color/black_color" />
        </TableRow>

        <TableRow
            android:id="@+id/TableRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="Treatment for "
                android:textColor="@color/black_color" />

            <TextView
                android:id="@+id/treatementfor"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:ellipsize="end"
                android:minLines="1"
                android:layout_weight="1"
                android:padding="5dp"
                android:singleLine="true"
                android:text="TextView"
                android:textColor="@color/black_color" />
        </TableRow>

        <TableRow
            android:id="@+id/TableRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="Horse Name "
                android:textColor="@color/black_color" />

            <TextView
                android:id="@+id/horsename"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginRight="10dp"
                android:ellipsize="end"
                android:minLines="1"
                android:layout_weight="1"
                android:padding="5dp"
                android:singleLine="true"
                android:text="TextView"
                android:textColor="@color/black_color" />
        </TableRow>

        <TableRow
            android:id="@+id/TableRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="Where "
                android:textColor="@color/black_color" />

            <TextView
                android:id="@+id/location"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:ellipsize="end"
                android:minLines="1"
                android:layout_weight="1"
                android:padding="5dp"
                android:singleLine="true"
                android:text="TextView"
                android:textColor="@color/black_color" />
        </TableRow>
</TableLayout>

It may work for you.

like image 63
Hemant Avatar answered Oct 27 '22 17:10

Hemant


//try this

        android:maxEms="9" this attributes will do change you maxEms according to your length what you want to achive.

<TextView
                android:id="@+id/productusedfor"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:ellipsize="end"
                android:minLines="1"
                android:padding="5dp"
                android:maxEms="5"
                android:singleLine="true"
                android:text="TextView"
                android:textColor="@color/black_color" />
like image 35
Padma Kumar Avatar answered Oct 27 '22 17:10

Padma Kumar