我必须在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行,意味着只需添加...
内容,如上例所示。我怎样才能做到这一点?
试试:
tv.setMaxLines(2);
tv.setEllipsize(TextUtils.TruncateAt.END);
尝试设置android:ems =“10”它会使你的edittext更广泛并包装文本
尝试为每个TextView将android:ellipsize设置为none。有关详细信息,请参阅有关此属性的文档
来自xml:
<TextView ... android:ellipsize="none" />
来自代码:
TextView textView = new TextView(context);
...
textView.setEllipsize(null);
您可以尝试在TextView
中为strings.xml
定义文本。然后,如果您从html设置,那么它可以根据屏幕大小进行换行:
所以你可以尝试一下:
<string name="nice_html">
<![CDATA[Don'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)));