简体   繁体   English

如何在文本视图中向左对齐第二个单词并向右对齐

[英]How to aligne 2 words in textview one left and second right

Does anyone know how to aligne two numbers on one line in android textview so one is aligned left and second one right? 有谁知道如何在android textview中的一行上对齐两个数字,所以一个对齐左,第二个对齐右? Gravity doesnt help neither html.format... 重力没有帮助html.format ... 在此处输入图片说明 Btw:i need to be able to keep changing properties of the text like colors etc.. 顺便说一句:我需要能够不断更改文本的属性,例如颜色等。

I dont think this is supported by android. 我不认为这是由Android支持。 Maybe using justify could do it, but it only works on Oreo and beyond 也许使用justify可以做到,但它仅适用于Oreo或更高版本

https://stackoverflow.com/a/1293541/3885877 https://stackoverflow.com/a/1293541/3885877

Else I would try a custom text view, where the 2 texts are aligned to the sides. 否则,我将尝试使用自定义文本视图,其中2个文本与侧面对齐。

But I don't think you can achieve this very easy. 但我认为您无法轻松实现这一目标。

所以我通过添加第二个textview解决了

You could use dynamic strings with strings.value for this. 您可以为此使用带有string.value的动态字符串。 For example: in strings.xml add this: 例如:在strings.xml中添加以下内容:

<string name="left_and_right_alignment">%1$s %2$s</string>

and in your class you can use: 在您的课程中,您可以使用:

getContext().getResources().getString(R.string.left_and_right_alignment, "left", "right")

Hope this helps. 希望这可以帮助。

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

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