简体   繁体   中英

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? Gravity doesnt help neither 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. Maybe using justify could do it, but it only works on Oreo and beyond

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

Else I would try a custom text view, where the 2 texts are aligned to the sides.

But I don't think you can achieve this very easy.

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

You could use dynamic strings with strings.value for this. For example: in strings.xml add this:

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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