- 我有一个 TableLayout,我需要在运行时添加 TableRows。
- 我需要为每个 TableRow 添加一个 ImageView 和一个 TextView,并将该行添加到 TableLayout。
- 如果文本的长度很长,添加到每一行的 TextView 应该多行显示。
- 我尝试了 setSingleLine(false)、setMaxWidth(100)、setMaxLines(3),但没有任何效果,但是如果我在 xml 中添加 TableRow 并使用 android:singleLine="false" 它会以多行显示文本。
请给我建议.......
通过此代码解决
TableRow.LayoutParams tlparams = new TableRow.LayoutParams(
TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT);
TextView textView = new TextView(this);
textView.setLayoutParams(tlparams);
textView.setText("New text: " + s);
textView.setSingleLine(false);