Question

I have an app that is pulling information from a json file:

{
 "EVENTS": [
        {
            "what": " TABLE-QUIZ",
            "who": "anyone",
            "when": "31st January",
            "where": "ABC HELLO"
        }
    ]    
}

When I run the app, sometimes the text in the column When is cut off on smaller screens when it goes onto a second line. If the text in the What column is too big it will go onto a second line and not get cut off. Why is the When column not going onto the second line while the What column is?

enter image description here

Here is the layout xml that I am using:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:shrinkColumns="*"
android:stretchColumns="*" >

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

    <TextView
        android:id="@+id/what"
        android:layout_width="0px"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@drawable/textlines"
        android:gravity="center"
        android:textColor="#fff"
        android:textSize="12sp" >

    </TextView>

    <TextView
        android:id="@+id/when"
        android:layout_width="0px"
        android:layout_height="match_parent"
        android:layout_weight="0.65"
        android:background="@drawable/textlines"
        android:gravity="center"
        android:textColor="#fff"
        android:textSize="12sp" >
    </TextView>

    <TextView
        android:id="@+id/where"
        android:layout_width="0px"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@drawable/textlines"
        android:gravity="center"
        android:textColor="#fff"
        android:textSize="12sp" >
    </TextView>

    <TextView
        android:id="@+id/forWho"
        android:layout_width="0px"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@drawable/textlines"
        android:clickable="true"
        android:gravity="center"
        android:onClick="onClick"
        android:textColor="#fff"
        android:textSize="12sp" >
    </TextView>
</TableRow>

</TableLayout>

EDIT: If I add:

android:minHeight="30dp"

to the TextView then I can get it to display the two lines, but I am hoping for a solution that will work automatically.

Was it helpful?

Solution

The problem is that you set TableLayout's width (parent's width) to wrap_content. Setting it to match_parent like this

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

makes When column go to the next line without being cut off.

OTHER TIPS

You need to view the full data means add this on Textview

android:singleLine="false" 

Hope this one will helps you.

Change android:layout_weight to 1 and android:layout_width in all the TextViews to 0dp, so that layout_weight="1" property can work.

Hope this helps!

I hope this helps

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:shrinkColumns="*"
    android:stretchColumns="*" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal" >

        <TextView
            android:id="@+id/textView41"
            android:text="when"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/textView42"
            android:gravity="center_horizontal"
            android:text="28°C" />

        <TextView
            android:id="@+id/textView43"
            android:gravity="center_horizontal"
            android:text="where" />

        <TextView
            android:id="@+id/textView44"
            android:gravity="center_horizontal"
            android:text="what" />

        <TextView
            android:id="@+id/textView44"
            android:gravity="center_horizontal"
            android:text="for who" />

    </TableRow>
</TableLayout>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top