How to create vertically aligned superscript and subscript in TextView

后端 未结 6 884
醉话见心
醉话见心 2020-12-08 22:37

In the example of image below:

\"enter

How can I make both the superscript and

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 23:34

    I would not try to bend the TextView widget to make that. Instead, you could easily make your own widget that has 2 different paints: one for the element name (big font size) and one for the numbers (small size, italics).

    You'd make proper setters and store each property separatly instead of storing a big spannable or string.

    You'd also be able to easily align both horizontally and vertically (numbers at top and bottom of element name)

    To compute the width, you can have a property to adjust the padding between numbers and element name. Then you can use each paint to compute the text width and add all this (don't forget to add the widget padding values).

提交回复
热议问题