简体   繁体   English

在列表视图中显示 html 格式 android

[英]Display html formatting in listview android

I've got a list view in which i have to dispaly some text from html with proper formatting.我有一个列表视图,我必须在其中以正确的格式显示 html 中的一些文本。 Though i pass the html as string to Html.fromHtml method but my formatting as align="justify" don't work.虽然我将 html 作为字符串传递给Html.fromHtml方法,但我的格式为align="justify"不起作用。

here is the code snippet:这是代码片段:

String text = "<ul><li><p><div align="justify">as part of its growth plan, the ranchi-based central coalfields ltd (ccl) is gearing up to double the company's production in the next couple of years and also to increase the capacity of coal washeries.</div></p></li></ul>";

i pass this this string to我把这个字符串传给

Spanned nText = Html.fromHtml(text);

and then i display it on the screen然后我将它显示在屏幕上

When String nText displays on the emulator screen the formatting that should be there, ie the text should be displayed as justified, is gone.当 String nText 在模拟器屏幕上显示时,应该存在的格式,即文本应该显示为对齐,消失了。

Please help请帮忙

I have found that using Html.fromHtml() can be somewhat hit and miss because some html tags are supported, and others are not.我发现使用 Html.fromHtml() 可能会有些碰碰运气,因为支持一些 html 标签,而其他标签不支持。 Justified text is not generally supported within Android mainly because, I suspect, that it can look pretty dreadful with relatively short lines of text. Android 中通常不支持两端对齐的文本,我怀疑这主要是因为它在相对较短的文本行中看起来很可怕。 It would not surprise me if justified text is not supported in fromHtml().如果 fromHtml() 不支持对齐文本,我不会感到惊讶。

Personally I would avoid justified text on a small screen anyway because it can be difficult to read.就个人而言,无论如何我都会避免在小屏幕上显示合理的文本,因为它可能难以阅读。

If you really need justified text, I think that you may need to write something which implements android.text.style.AlignmentSpan and write your own text justification routine, which will not be a trivial task.如果您真的需要对齐文本,我认为您可能需要编写一些实现 android.text.style.AlignmentSpan 的东西并编写自己的文本对齐例程,这不是一件容易的事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM