简体   繁体   English

Android TextView中的HTML文本对齐

[英]HTML text alignment in Android TextView

I have an HTML that includes 2 paragraphs: 我有一个包含2个段落的HTML:

<p style="text-align: center">centered text example</p>
<p style="text-align: right">alignment right text example</p>

I added it in my android TextView using Html.fromHtml 我使用Html.fromHtml将其添加到我的android TextView

As a result in my view first paragraph aligned center(as expected), but second paragraph doesn't aligned rigth and aligned to left . 因此,在我看来,第一段居中对齐(如预期), 但第二段未对齐向右对齐并向左对齐

How is it correct to set html alignment properties to make work it in android? 设置html对齐属性使其在android中工作如何正确?

Try using 尝试使用

"text-align: end" 

instead of 代替

"text-align: right"

That is because for some reason Html.fromHtml supports start , center and end as text-align values. 这是因为出于某些原因, Html.fromHtml支持将startcenterend作为text-align值。 It does not match CSS, but that's how it works. 它与CSS不匹配,但这就是它的工作原理。

Proof 证明

change 更改

"text-align: right"

to

"text-align: end"

in your inline css 在您的内联CSS中

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

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