Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView content inside a Table Row gets cut off

Firstly, I did a Google search and looked at StackOverFlow questions related to text being cut off for TextView. They did not help to solve the problem at hand, though they provided better understanding of certain things.

Here is my problem.

I am using TableLayout to display records with two text fields. Each row has two TextView cells. layout_width is set to wrap_content for all cells. But, even though the text is displayed in multiple lines, every line in that multi-line text is cut off at the end.

e.g.

   <?xml version="1.0" encoding="utf-8"?>
   </TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content">
   <TableRow>
        <TextView
            android:text="Notes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/visitation_notes" />
        <TextView
            android:text="Need to visit again. Visit till the doctor understands the importance of the Test. The problem is, it is very difficult to get appointment for the visit. Still, we need to keep trying till the point reaches to him/her."
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/visitation_notes_value"
            android:textAlignment="viewStart"/>
   </TableRow>
   </TableLayout>

produced the view

Notes.Need to visit again. Visit till the doctor understands the importance of the Test. The problem is, it is very difficult to get appointment for the visit. Still, we need to keep trying till the point reaches to him/her.

with the text written in bold getting cut off.

If I use LinearLayout in place of TableLayout, it works fine. But, the problem with that is I can't have second column of each row starting at same position(with no hardcoding).

Please help me how to make sure TextView content won't get cut off.

Here is the screenshot of view produced for example given above.

like image 212
Satish Thulva Avatar asked Mar 10 '23 07:03

Satish Thulva


2 Answers

Do this

<TableRow>


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Note" />

    <TextView
        android:layout_weight="3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:text="Need to visit again. Visit till the doctor understands the importance of the Test. The problem is, it is very difficult to get appointment for the visit. Still, we need to keep trying till the point reaches to him/her." />


</TableRow>
like image 185
saumil patel Avatar answered Mar 21 '23 07:03

saumil patel


I got the truncated TextView inside a TableRow element issue resolved with the following code:

<TableRow>

    <TextView
        android:layout_gravity="right"
        android:text="Address: "
        android:textStyle="bold"/>

    <TextView
        android:id="@+id/address"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingRight="10dp"
        android:text="123 W. Abc St., San Diego CA 90333"/>

</TableRow>
like image 30
Gene Bo Avatar answered Mar 21 '23 06:03

Gene Bo