【问题标题】:Android TextView and text wrappingAndroid TextView 和文本换行
【发布时间】:2014-03-17 15:43:19
【问题描述】:

我在 TableRow 中有一个 TextView。此 TextView 中包含的文本通常比屏幕大。因此,我希望将文本换成多行。

TableLayout table = (TableLayout)findViewById(R.id.myTable);
TableRow row = new Tablerow(context);
TextView view = new TextView(context);
view.setText(stringWithLotsOfCharacters);
view.setSingleLine(false);
row.add(view);
table.addview(row, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

我尝试使用“setSingleLine”,但没有达到我想要的效果。

有什么建议吗?谢谢。

【问题讨论】:

    标签: android textview


    【解决方案1】:

    为您想要换行的列添加android:shrinkColumns="1" 到布局中的TableLayoutandroid:shrinkColumns="*" 如果您想要换行所有列。

    您也可以使用 setColumnShrinkable 以编程方式进行:

    public void setColumnShrinkable (int columnIndex, boolean isShrinkable)
    

    【讨论】:

      【解决方案2】:
      view.setHeight(LayoutParams.WRAP_CONTENT);
      

      【讨论】:

      • 谢谢,但没用。文本不再出现。我刚刚用我的更多代码编辑了第一篇文章。
      • LayoutParamsLayoutParams 是什么?
      • android:layout_width="wrap_content" android:layout_height="wrap_content"
      • 将表格的layout_width 设置为fill_parent,并且最好将您的视图设置为相同,例如view.setWidth(LayoutParams.FILL_PARENT);.
      • @MattBishop 这是错误的伙伴。如果你连续有一个以上的列会发生什么?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-01
      • 1970-01-01
      • 2012-06-14
      相关资源
      最近更新 更多