TextView并不总是在TableLayout中扩展到第二行 [英] TextView not always expanding to a second line in TableLayout

查看:93
本文介绍了TextView并不总是在TableLayout中扩展到第二行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序正在从json文件中提取信息:

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列中的文本会在较小的屏幕上被截断.如果What列中的文本太大,它将进入第二行,并且不会被截断.为什么When列不在What列的第二行上?

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?

这是我正在使用的布局xml:

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>

如果我添加:

android:minHeight="30dp"

TextView,然后我可以显示两行,但是我希望找到一种可以自动运行的解决方案.

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

推荐答案

问题是您将TableLayout's width(父母的宽度)设置为wrap_content.像这样将其设置为 match_parent

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"
    ...

使When列不中断而转到下一行.

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

这篇关于TextView并不总是在TableLayout中扩展到第二行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆