Android::TextView::Programitic Creation with setSingleLine(false) - 不换行

标签 android textview

我以编程方式将 textview 设置为 TableRow View 的 subview ,但我似乎无法让文本包含在父 View 中。

这是应该将文本包装在 TableRow 中的代码。请注意 setSingleLine 被设置为 false。

            TextView value = new TextView(this);
    ![alt text][1]value.setLayoutParams(new TableRow.LayoutParams(
            LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));

    value.setSingleLine(false);
    value.setEllipsize(TruncateAt.END);
    value.setHorizontallyScrolling(false);

    value.setText(txt);
    value.setTextColor(Color.BLACK);
    value.setTextSize(12);
    value.setTypeface(generalFont);

文档没有说将它设置为 false 会使它成为多行,它说它将恢复为默认值。

setSingleLine(boolean singleLine) If true, sets the properties of this field (lines, horizontally scrolling, transformation method) to be for a single-line input; if false, restores these to the default conditions.

是否有人有指向以编程方式创建的多行 TextView 的代码 fragment 或 URL?

TextView 中的文本

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus tempus porttitor diam, sit amet rutrum nunc laoreet at. Mauris sit amet tristique e

显示问题的图像

TextView not wrapping

最佳答案

问题结束了它成为祖 parent (TableLayout)。我不得不缩小所有列并将文本换行。

table.setShrinkAllColumns(true);

关于Android::TextView::Programitic Creation with setSingleLine(false) - 不换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3704854/

相关文章:

java - 设置每行的 Edittext 背景

Android:如何在 TextView 中对齐文本?

android - 如何打开图像以在其上绘制

android WebView 无法正常工作

android - 无法在空对象上调用方法 version()

android - 滚动回收器 View 时如何防止项目重复

android - 无法垂直居中 textview 的文本

android - 删除 TextView 的背景

android - 在android中制作超链接textview

android - 使用 PrintedPdfDocument 和 View.draw 从 Android 生成 PDF