LIN Yu-Cheng
LIN Yu-Cheng

Reputation: 53

Android: different layout to support different fontSize

User can change font size in system setting and I use "sp" in xml layout.

Android use different folder to support multi-screen, is there any way to change layout when user change font size?

like this:

res
   layout
   layout-bigfont
   layout-normalfont

Upvotes: 4

Views: 1400

Answers (1)

Ted Hopp
Ted Hopp

Reputation: 234857

Sorry, but the answer is no. The Android documentation on providing alternative resources has a comprehensive list of what configuration attributes are considered when binding resources. Unfortunately, text scaling is not one of the attributes.

The best you can do is detect the font scaling yourself and load alternative resources in code:

float scale = getResources().getConfiguration().fontScale;

Larger text will have scale > 1.

Upvotes: 5

Related Questions