Responsive font size in Android - android

We can make positioning of widgets 'responsive' by using bias/weight etc, but how do we make the font sizes responsive? By 'responsive' I mean the font size that changes according to size of device - i.e for large device the font size will be large, and for small device the font size will be small.
I tried using the library for ssp/sdp, but that didn't solve the issue.
Another suggested way is to create different font sizes in dimens.xml for different device size, and use them, but that would require calculating the different font sizes for the fonts used in the entire app.
Is there any other way?

you can use this library for font size :
implementation 'com.intuit.ssp:ssp-android:1.0.6'

Related

TT-Chocolates font not rendering properly in small sizes

I've started using the font TT-Chocolates font in an Android app, but with font sizes < 16sp the font is being rendered uneven/inconsistently (e.g. TT-Chocolates-Regular 14sp, full resolution screenshot taken with android studio 1080x2400 Poco X3):
As you can see e.g. the "r" letters is drawn differently in two different textviews (list of elements with the exact same style and font size). In iOS, with the same size this problem does not occur.
Any thoughts? Thank you very much in advance!

How to scale text relative to screen size?

I want to display some values on screen such that they occupy roughly the same percentage of screen area irrespective of display size or pixel density. How do I do that?
When I use dp or sp I get the following results for the same font size a tablet and on a phone.
One a 1280x768 4.7 inch phone:
On a 1280x800 10 inch tablet:
Try using SDP library for mentioning dimens in your XML file.
After that there will be no need to prepare multiple layout files.
Please check this library,
that provides a new size unit - sdp (scalable dp). This size unit scales with the screen size. It can help Android developers with supporting multiple screens.
You've to create different layout folder, for instance for devices like 7" tablet (600x1024 mdpi), you'll have to create the folder res/layout-sw600dp/ and in there put the layout that you want to display on screens that has this screen-size and change for instance the TextView text size, position on the screen, etc...
I recommend you to read the Support different screen sizes documentation, there's well explained how to do that.
Also you have other way to do that, it's better the first one, but I personally used this library and it worked well for me because the layout were not that big.
Test this SDP - a scalable size unit library, then you do now have to create different layouts or yes deppends of your likes

Font size in XML for Android Wear resolutions

How can I have different xml font sizes for different Android Wear Watches?
Currently there are 280/320/360/400/480 resolution watches. I adjust my fonts programmatically after I detect the screen size with onSurfaceChanged();
Can I have different .xml for different resolution and how should I define it? It will be a lot more better solution and it will cut my code a lot.

Android font size in pt

I'm working on a Android project where I need to build my layouts based on a JSON layout file. This same file is also being used on an iOS app. So there is 1 file which will render the same layout on the Android as well as on the iOS.
The JSON layout file defines its font sizes based on the default iOS font unit.
From the Android docs:
Points - 1/72 of an inch based on the physical size of the screen.
And as far as I can find, iOS font sizes are also defined as 1/72 of an inch.
So based on this info, I'd say the following should be enough:
view.setTextSize(TypedValue.COMPLEX_UNIT_PT, fontSizeInIosUnit)
This however results in the text being too large. And it also seems to differ per device (which is weird since points should always appear in the same physical size).
If you want fonts to resize properly according to screen size you should use dp/dip instead.
So try this instead:
view.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSizeInIosUnit);
Now this might not be exacly the same but in my experience this gives the best results. If it doesn't have the proper size then figure out what size you need on Android as the base size and then go with that instead.

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?
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.
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.
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.

Categories

Resources