0

Before someone says that I should google this, I want to point out that I did and then i tried all the different methods to see what would work and nothing did for me. So, now that ugly business is out of the way on with my questions.... :)

I cannot seem to get a text view to wrap for me. Dont know why. Here is my XML code for the layout. It is a table layout that will be used for a listview in another xml layout.

<?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="match_parent">
    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/ot_color_priority"
            android:layout_height="fill_parent"
            android:layout_width="20dp"
            android:gravity="center_vertical"/>
        <RelativeLayout>
            <TextView
                android:id="@+id/ot_ticket_number"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:gravity="center"
                android:textStyle="bold"/>
                <TextView
                    android:id="@+id/ot_ticket_details"
                    android:layout_alignParentBottom="@id/ot_ticket_number"
                    android:layout_height="wrap_content"
                    android:layout_width="300dp"
                    android:layout_marginTop="15dp"
                    android:scrollHorizontally="false"
                    android:ellipsize="none"
                    android:maxLines="10"
                    android:text="This is a long dang string that never wants to freaking wrap worth a crap!"/>
        </RelativeLayout>
    </TableRow>
</TableLayout>

The data that is in the textview just continues to write off the screen to the right. I cannot get it to wrap. The only way I can seem to get it to work is if I set a DP value to the layout_width. I dont want to do that because it will be used on different devices screen resolutions and I am afraid that may cause some problems later on.

So please someone help me :(

BinaryNexus
  • 875
  • 3
  • 15
  • 30

2 Answers2

3

You should set android:shrinkColumns="1" to your TableLayout.

It will shrink the second column which is occupied by RelativeLayout.

waqaslam
  • 67,549
  • 16
  • 165
  • 178
  • I could have swore that I tried this already but this seemed to fix it. – BinaryNexus Aug 18 '14 at 12:02
  • Thanks this worked for me. @waqaslam please do you think you could give me your opinion on this question http://stackoverflow.com/questions/25598696/recommended-way-order-to-read-data-from-a-webservice-parse-that-data-and-inse – Axel Sep 02 '14 at 03:10
1

It's probably your RelativeLayout which does not have any width specified, so it is defaulting to "WRAP_CONTENT" :

http://developer.android.com/reference/android/widget/RelativeLayout.html#generateDefaultLayoutParams()

I should also point out that inside that TextView you have a child with a "match_parent" width, but the relative layout will sit next to an element with a "20dp" width.

<?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="match_parent">
    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/ot_color_priority"
            android:layout_height="fill_parent"
            android:layout_width="20dp"
            android:gravity="center_vertical"/>

        <!-- this is the problem, the layout has no parameters set    -->
        <RelativeLayout>
            <TextView
                android:id="@+id/ot_ticket_number"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:gravity="center"
                android:textStyle="bold"/>
                <TextView
                    android:id="@+id/ot_ticket_details"
                    android:layout_alignParentBottom="@id/ot_ticket_number"
                    android:layout_height="wrap_content"
                    android:layout_width="300dp"
                    android:layout_marginTop="15dp"
                    android:scrollHorizontally="false"
                    android:ellipsize="none"
                    android:maxLines="10"
                    android:text="This is a long dang string that never wants to freaking wrap worth a crap!"/>
        </RelativeLayout>
    </TableRow>
</TableLayout>
Jim
  • 10,172
  • 1
  • 27
  • 36
  • This is very helpful information but it didnt directly solve the problem. Adding the shrink column did help. But I still like your answer as well. Thank you! – BinaryNexus Aug 18 '14 at 12:03