Android并在TableRow的TextView中显示多行文本

SK9*_*SK9 49 android multiline tablelayout textview tablerow

我正在显示一个带有行的TableLayout,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<TableRow
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content">

  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

        <TextView   
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/one"
            android:layout_marginLeft="10dip"
            android:textColor="#B0171F" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/one"
            android:id="@+id/two"
            android:layout_marginLeft="10dip"
            android:ellipsize="none"
            android:singleLine="false"
            android:scrollHorizontally="false"
            android:maxLines="10"
            android:textColor="@android:color/black" />

  </RelativeLayout>

</TableRow>
Run Code Online (Sandbox Code Playgroud)

我正在使用我能在这里找到的所有东西,并且可以想到允许文本包裹在许多行上,但无济于事:文本总是被强制为一行,从屏幕上运行.我在这里工作在TableRow中可能很重要,据我所知,这个网站没有得到处理.

那么,如何强制我的第二个TextView包装到多行呢?

Mic*_*ann 98

如果文本的列设置为缩小,TextView将包装文本.有时它不会完全包裹,如果文本以",..."结尾,那么它比n行更长一点.

这是一个例子,带有id的TextView question将换行:

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:shrinkColumns="*">
    <TableRow>
         <TextView
             android:id="@+id/question"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"/>
    </TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)

  • @All:`android:shrinkColumns ="0"`对我来说很完美,而不是我一直在尝试的`android:shrinkColumns ="1".我不确定这是不是你的建议,但你的答案是可靠的,我的评论出现在这里.他们一起回答了我的问题. (12认同)
  • @ SK9答案是对的,但有点草率.这里的目的是使文本的列缩小,因此应该在该参数中设置列的索引.我已经更新了答案,希望它现在变得更加清晰. (2认同)

SK9*_*SK9 14

为了完整起见,这是我TableLayout读取XML的方式:

<TableLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_marginTop="10dp"
  android:shrinkColumns="0"
  android:stretchColumns="0"
  android:id="@+id/summaryTable">
</TableLayout>
Run Code Online (Sandbox Code Playgroud)

我后来用TableRows 填充了这个.