Ok I know that there are already many questions that ask the same thing as what I am asking, however the problem is that none of those solutions have worked for me or are what I want. My problem is that when I use the setTextSize method of the Paint class, the text appears to be too big on smaller screens, and smaller on bigger screens. What I want is for me to be able to change it to the size I want on my device, and then on any other device the size should change accordingly (scale down, scale up) and it should appear the same way (NOT the same size) on other devices. And I have already tried multiplying the density by the dp I want and all that other stuff but it doesn't work.
Asked
Active
Viewed 473 times
0
-
Use dimens.xml file under res to control different text size for different devices. Check this **http://stackoverflow.com/questions/21280277/different-values-folders-in-android** – Nabin May 05 '15 at 01:39
-
What text scaling factor should I use? So if I like a certain size in one screen how do I scale to other screen densities from THAT number? – user3698077 May 05 '15 at 02:02
-
Wait isnt this the same thing as multiplying a number by the density (i.e. if I wanted to use 16 dp I do: 16 * ...DisplayMetrics.density). I said I've already tried this and it doesn't work for me that's why I am posting the question. – user3698077 May 05 '15 at 02:07
-
You don't need to do multiplication or anything. Just create different dimens.xml files for different sized devices and put the text sizes in them. That will do – Nabin May 05 '15 at 02:18
-
But then I will have to go through every single phone to figure out text sizes for each one... there are so many phones out there I don't want to have to go through each one... – user3698077 May 08 '15 at 03:16
1 Answers
0
First off, any size you use should be based off of sp- scaled pixels. Units in sp scale with respect to the user defined default size. This is to people who are hard of seeing can choose a larger text size, and all text will scale relative to this choice. You should not be designing text in either dp or in px, as neither of those will scale with the system font size. When you call getTextSize/setTextSize it should be treated as sp.
As for it looking the exact same on all screens- you're not going to get that, because different OEMs use different default heights and different default fonts, not to mention the user can override either of those. Pixel perfect should not be your goal. Which is good, because it isn't actually possible.

Gabe Sechan
- 90,003
- 9
- 87
- 127
-
But my text (the highscore) is inside of like this board thingy and I need a way for it to maintain the same appearance (i.e. appear the same on different devices). Because what happens is that on a smaller device the text goes past the boundaries of the board thingy, making it appear very unprofessional. There has to be a way to make text appear similar on different devices without going through every single device and trying out every single text size to see which one fits with which device... – user3698077 May 08 '15 at 03:14
-
Welcome to the wonderful world of development. For your next trick, try translating to spanish and see how it looks- half the words will be twice as long and nothing will fit. – Gabe Sechan May 08 '15 at 03:15
-
So then how do other games do it? You're saying stuff is impossible when it's already been done... And translation is a different thing I can handle that as long as I know how to scale one language appropriately the rest will simply be repeating that but for each language I want. I just need the trick to scaling a set piece of text depending on the screen. – user3698077 May 08 '15 at 03:17
-
I'm not saying its impossible. I'm saying its usually not the right thing to try to do. Generally you try to leave a lot more room than you need, so it fits on smaller screens. But yes, you do redesign for different sizes. There are some things you can do programatically, like calculating the size of text via paint.measure in a loop to find a size that fits, but they're very expensive. Generally you test and make it work on small phones, normal, large, and tablets, and tweak the values for each. – Gabe Sechan May 08 '15 at 03:47
-
Oh and btw- translation is HARDER to fix than the multiple sizes thing, because you generally don't want to redesign for languages. Or at least you try to avoid it. – Gabe Sechan May 08 '15 at 03:48
-
So I should have different values folders for different densities and put different pixel sizes in the dimens.xml files of each and reference them by code? – user3698077 May 08 '15 at 22:21