Ellipsize" END"没有正常工作

时间:2014-04-30 12:03:32

标签: android

我试图以这种方式以编程方式创建TextView:

TextView textDescription = new TextView(this);
LinearLayout.LayoutParams layoutParamsDesc = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 25);
layoutParamsDesc.setMargins(10, 0, 10, 0);
textDescription.setLayoutParams(layoutParamsDesc);
textDescription.setText("Lengthy text in TextView");
linearLayoutDatos.addView(textDescription);
textDescription.setEllipsize (TextUtils.TruncateAt.END);
textDescription.setMaxLines(1);
textDescription.setHorizontallyScrolling(false);

然而,没有"三个点"显示。

我做错了什么?

提前致谢。

4 个答案:

答案 0 :(得分:1)

你写了textDescription.setMaxLines(1);但正确使用它的方法如下:

单行

textDescription.setSingleLine(true);

对于多行(超过1)

textDescription.setMaxLines(2);

另一方面,在使用textDescription完成所有设置后写下此行。

linearLayoutDatos.addView(textDescription);

所以最后会是这样的:

TextView textDescription = new TextView(this);
LinearLayout.LayoutParams layoutParamsDesc = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 25);
layoutParamsDesc.setMargins(10, 0, 10, 0);
textDescription.setLayoutParams(layoutParamsDesc);
textDescription.setText("Lengthy text in TextView");
textDescription.setEllipsize (TextUtils.TruncateAt.END);
textDescription.setSingleLine(true);
textDescription.setHorizontallyScrolling(false);
linearLayoutDatos.addView(textDescription);

答案 1 :(得分:0)

添加textDescription.setSingleLine()

答案 2 :(得分:0)

您必须设置maxLength的{​​{1}}属性。您可以这样做:

TextView

答案 3 :(得分:-1)

试试这个......

textDescription.setEllipsize (TextUtils.TruncateAt.MARQUEE);
相关问题