Making first word/character of string in textview bigger

放肆的年华 提交于 2019-12-23 01:18:29

问题


I have been searching online but haven't managed to find something that I could use. I have text in my textview that will have text something like;

1 Person
2 Person
3 Person

the text is formatted like this (1\nperson), (2\nperson) .... so adding space between the number and the person string.

What I want to do is make the number of each string bigger. For example;

I have searched online and the links / similar things I found are not that helpful:

Is it possible to have multiple styles inside a TextView?

TextView with different textSize

The default font size for the textview is 15, so the person string font size will always be 15, what I want to do is make the numbers bigger, for example to font size 20.


回答1:


I think this would work:

Spannable span = new SpannableString(textView.getText());
span.setSpan(new RelativeSizeSpan(1.5f), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(span);



回答2:


Why don't you use two TextViews inside a LinearLayout instead of one TextView? It will do what you need. You would put the first character in the first TextView and the rest of the String in the second TextView. If you need help doing that let me know.



来源:https://stackoverflow.com/questions/34956796/making-first-word-character-of-string-in-textview-bigger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!