2

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.

Onik
  • 19,396
  • 14
  • 68
  • 91
Howli
  • 12,291
  • 19
  • 47
  • 72
  • Hi, Howli! Sorry for disturbing! Do you mind reopening the [4-years-old question](https://stackoverflow.com/q/20869067/3290339). There are few alternative answers the question is lacking of. Those answers are worth to be relieved and might be especially helpful for AOSP starters. Thanks in advance! – Onik Sep 14 '18 at 20:56

4 Answers4

2

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.

Onik
  • 19,396
  • 14
  • 68
  • 91
1

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

android:singleLine="false" 

Hope this one will helps you.

Siva
  • 457
  • 4
  • 17
0

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!

Marko
  • 20,385
  • 13
  • 48
  • 64
Fareya
  • 1,523
  • 10
  • 11
  • 1
    That does work, but then each column has the same width, I need the `When` column to be smaller than the others. – Howli Apr 18 '14 at 23:02
0

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>
Marko
  • 20,385
  • 13
  • 48
  • 64
Pankaj Arora
  • 10,224
  • 2
  • 37
  • 59