jeudi 30 juin 2016

How do I increase the text size in my android textview based on loaded text?

I have a textview that displays text I load from a database. Sometimes the text is a single letter like b and sometimes it's two words that go over two lines like small word.

If I display a single letter I want the font size to be bigger. I tried using the html font tag with the size attribute and pass the string through Html.fromHtml():

<font size='6'>d</font>

However unfortunately the font size doesn't change and Android doesn't seem to recognize the attribute.

I don't want to give the font size in px because the I sometimes want to load the text in textviews with a different default textsize.


More detail: I have an app that asks the user a series of questions. To do so it displays two possible answers in two separate textviews. I have a few thousand questions in my database. The activity runs for 3 minutes at a time and I expect the user to answer a question every three seconds.

Sometimes the answer is a one-line word, sometimes it's take two lines and sometimes it's a single letter. In cases where it's a single letter I feel like I'm wasting space by displaying the letter in the same textsize, so I want to increase it's textsize.

In the field where the question is displayed, I have a similar issue. Sometimes the question takes two lines and sometimes it takes a short one-line word. When it takes one-line I also want to increase the font size.

Aucun commentaire:

Enregistrer un commentaire