badgerduke
badgerduke

Reputation: 1013

trouble with font size for different screen size/resolution

I know this has been answered in other questions, but nothing is working for me. I have a text view where I want the text to appear the same size in a variety of density/screen size combinations. I have tried specifying

android:textSize="30dp"

and

android:textSize="30sp"

and have also used

TextView text = (TextView) findViewById(R.id.text);
text.setTextSize(30 * (getResources().getDisplayMetrics().density));

30 is my font size *****

the text doesn't scale properly. It becomes way too small at lower densities and as screen size increases. Are there additional techniques I can use to scale my font?

Upvotes: 0

Views: 233

Answers (3)

0xC0DED00D
0xC0DED00D

Reputation: 20348

If you just want to have separate font sizes for separate screens, you can create dimens in your value.xml for sw600dp and sw720dp folder too and put different values there. You don't need to create separate xml layout for each, if you just need to change font sizes.

Upvotes: 0

Zulaxia
Zulaxia

Reputation: 2732

After years of constantly having everything slightly off on different devices, I recently discovered that the inches and cm measurements for dimensions are literally that.

So even on devices where 160dp isn't quite an inch, specifying 1inch will give exactly that, on everything, even if they have a custom scaled ROM.

I now specify anything I want very tight control over with these.

Upvotes: 0

FoamyGuy
FoamyGuy

Reputation: 46846

create layout-large, layout-small, layout-xlarge etc.. versions of your layout xml file.

You can set the size differently in each so that the font will look right across a variety of screen sizes.

Upvotes: 1

Related Questions