Android 并在 TableRow 的 TextView 中显示多行文本
我正在显示一个带有行的 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>
我正在使用我在这里可以找到的所有内容进行此操作,并且可以想到允许文本换行多行,但无济于事:文本始终被强制为单行,跑出屏幕。我在这里的 TableRow 内工作可能很重要,据我所知,该网站尚未对此进行处理。
那么,如何强制我的第二个 TextView 换行多行?
I'm displaying a TableLayout with rows as follows:
<?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>
I'm hitting this with everything I can find here and can think of to permit the text to wrap on many lines but to no avail: The text is always forced to a single line, running off the screen. It might matter that I'm working inside a TableRow here, and so far as I can tell this hasn't been treated on this site.
So, how do I force my second TextView to wrap to many lines?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果 TextView 所在的列设置为收缩,则 TextView 将包裹文本。有时它不会完全换行,如果文本以“,...”结尾,那么它比恰好n行要长一点。
下面是一个示例,带有 id
question
的 TextView 将换行:The TextView will wrap the text if the column it's in is set to shrink. Sometimes it does not wrap exactly, if the text ends with ", ...", then it is a little bit longer than exactly n lines.
Here's an example, the TextView with the id
question
will wrap:为了完整起见,这就是我的
TableLayout
在 XML 中的读取方式:稍后我用
TableRow
填充它。For the sake of completeness, this is how my
TableLayout
reads in XML:I later populate this with
TableRow
s.通过代码也可以:
1 是列数。
By code also works:
1 is the number of column.
也许尝试如下:
我知道,看起来有点像“轮椅”解决方案,但对我有用,尽管我也以编程方式填充文本。
Maybe try as follows:
I know, looks a bit like a "wheelchair" solution, but works for me, though I also fill a text programmatically.
您还可以使用下面的代码
You can also used below code