I want to write a line in a TextView where the second word is a quarter of the size of the first word. In my string.xml file I used large and small and it did not work to the extent I want it to. I also tried changing the text size in the main.xml, but it only lets you do that once in a TextEdit. Any ideas?
Asked
Active
Viewed 3,628 times
3 Answers
4
If what you need is to specify different font sizes for the text in a TextView from XML you can assign a string like this:
<string name="hello"><big><big>Hello Big Text!</big></big>\n<small>Hello small text</small></string>
and use this string in the TextView. Note that the newline is '\n
' instead of <br/>
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:text="@string/hello" />

Diego Torres Milano
- 65,697
- 9
- 111
- 134
1
Take a look at this question: Is it possible to change the text color in a string to multiple colors in Java?
But instead of ForegroundColorSpan
you should use TextAppearanceSpan
or AbsoluteSizeSpan
.
-
In the java it is possible. I am wondering if I can do it in the xml – Aaron Dec 12 '11 at 23:17
-
No, you can't. You'll need to use java one way or the other. – inazaruk Dec 12 '11 at 23:29