2

I have read Different font sizes for different screen sizes, but I found that is not working well for me.

I created a values-hdpi to define styles, but I found both 480x800 and 1280x760 use it -- the screen size is so different!

Is there any way to let 480x800 screen use one font size and 1280x760 use another one?

Community
  • 1
  • 1
Freewind
  • 193,756
  • 157
  • 432
  • 708
  • Use the sp unit. (which is the same as dp, but for fonts) This will ensure that the size is scales based on dots-per-inch (dpi). – Deepak Swami Sep 12 '12 at 04:36
  • 3
    no. SP is the same as DP, but it gets scaled up or down if the user chooses larger / smaller fonts at the system level, in their preferences: http://developer.android.com/guide/topics/resources/more-resources.html#Dimension – Jeffrey Blattman Sep 12 '12 at 04:46

1 Answers1

3

Yes.

Create screen-specific dimensions files, like this,

values-sw720dp/dimens.xml
values-sw600dp/dimens.xml
values/dimens.xml

The first is for 10" tablets, the second is for 7" tablet, and the last is for phones. If that doesn't give you the gradations you want, read this page to find out other ways of targeting different screens.

In those files, define a dimension,

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen
        name="my_size">40sp</dimen>
</resources>

adjust the dimension value in each of the dimens.xml files to your liking.

Now in your layout,

<TextView ...
  android:textSize="@dimen/my_size"/>
Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134