简体   繁体   English

在Android的Textview中对齐文本(使用Html.fromhtml())

[英]Aligning text in Textview for Android (using Html.fromhtml())

I'm trying to display this table of information. 我正在尝试显示此信息表。

It currently looks like 目前看起来像

[这个]

I want it to look like 我希望它看起来像

[这个]

Is there anyway to get this kind of alignment? 反正有这种对齐方式吗?

Right now, all of this text is in one TextView, and is styled by Html.fromhtml() 现在,所有这些文本都在一个TextView中,并由Html.fromhtml()设置样式。

So, conceivably, if there is an html solution to this problem, I could apply it to this textview. 因此,可以想象,如果有针对此问题的html解决方案,我可以将其应用于此textview。

The conventional response would be to compose an XML layout and set the fields individually. 常规的响应是组成XML布局并分别设置字段。 You could also just keep your HTML as-is and use a WebView instead of a TextView. 您也可以按原样保留HTML并使用WebView代替TextView。

You can use html table to achieve this. 您可以使用html表来实现此目的。 ex: 例如:

<table>
<tr><td>Session Id</td><td>1</td></tr>
<tr><td>Start time</td><td>xyz</td></tr>
</table>

String styledText = "sessionaID:1"; 字符串styledText =“ sessionaID:1”; textView.setText(Html.fromHtml(styledText)) textView.setText(Html.fromHtml(styledText))

I think ur doing same way. 我认为您的做法也一样。 If you need solution in HTML form only then simply append the space tag in front of 1. and similarly to next fields also. 如果仅需要HTML格式的解决方案,则只需将空格标记附加到1.之前,并将其类似地添加到下一个字段。 Means all the possible tag of HTML to get the same look. 表示HTML可能具有相同外观的所有标记。 solution) 解)

better way is just design a XML and U can set gravity and other parameter for text view 更好的方法是只设计XML,U可以为文本视图设置重力和其他参数

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

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