Android中的Textview包装

问题描述 投票:2回答:4

我必须在Textview feed中显示Android中的xml

让我们把这是我的Textview

Mallika Sherawat's upcoming movie Dirty Politics

在这里,我为这些Textview动态创建了布局:

LinearLayout.LayoutParams textLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 50);
textLayoutParams.gravity = Gravity.CENTER;

TextView tv = new TextView(this);
tv.setSingleLine(false);
tv.setEllipsize(null);
tv.setHorizontallyScrolling(false);
tv.setTextColor(Color.parseColor("#a7a9ac"));
tv.setText(Appscontent.Sub_arraylisttwo.get(j));
tv.setLayoutParams(textLayoutParams);
tv.setBackgroundColor(Color.parseColor("#414042"));

我在这里提到了宽度50。

所以文本显示在小内容Textview。有时我有更多的内容Textview这意味着我如何显示如下Textview

Mallika Sherawat's 
upcoming movie Dirty...

我的意思是文本只有在文本扩展后才能显示最多2行,意味着只需添加...内容,如上例所示。我怎样才能做到这一点?

android textview textwrapping
4个回答
5
投票

试试:

tv.setMaxLines(2);
tv.setEllipsize(TextUtils.TruncateAt.END);

1
投票

尝试设置android:ems =“10”它会使你的edittext更广泛并包装文本


0
投票

尝试为每个TextView将android:ellipsize设置为none。有关详细信息,请参阅有关此属性的文档

来自xml:

<TextView ... android:ellipsize="none" />

来自代码:

TextView textView = new TextView(context);
 ...
 textView.setEllipsize(null);

0
投票

您可以尝试在TextView中为strings.xml定义文本。然后,如果您从html设置,那么它可以根据屏幕大小进行换行:

所以你可以尝试一下:

<string name="nice_html">
<![CDATA[Don&apos;t worry we will never share this with anyone<br/>
By Clicking register you are indicating that you have read and agreed to the <br/>
 <u>Terms of services</u>  and <u>Privacy Policy</u>
]]></string>

然后,在您的代码中:

TextView foo = (TextView)findViewById(R.id.foo); foo.setText(Html.fromHtml(getString(R.string.nice_html)));
© www.soinside.com 2019 - 2024. All rights reserved.