1

How can I choose text size so that it looks the same on every device? I find it to be an impossible task, probably you will say that I should make different values for each dpi but that doesn't solve the problem, because there are phones with the same dpi but different screen resolution, and in the end it doesn't look the same. Anyone can help me here?

Greyshack
  • 1,901
  • 7
  • 29
  • 48

2 Answers2

0

The Android guidelines suggest to use the SP dimension for text: http://developer.android.com/training/multiscreen/screendensities.html

An SP dimension is dependent on the screen density but also user preferences. Let's say a user configures his phone for big font (vision problems for example) your app will be accessible for this user.

In practice it looks like this: textSize="16sp"

Quanturium
  • 5,698
  • 2
  • 30
  • 36
  • It doesn't help at all. – Greyshack Feb 23 '15 at 19:22
  • What you are trying to do is going against best practices. I would suggest to rethink it. However if you still want to do this, take a look here on how to get the screen size http://stackoverflow.com/questions/1016896/get-screen-dimensions-in-pixels Once you have the screen size, you can easily factor it to calculate a "same" size for all font on different densities / screen resolutions. – Quanturium Feb 23 '15 at 19:27
  • Why is it against best practices? – Greyshack Feb 23 '15 at 19:36
  • I mentioned it in my answer. By using the sp dimension the user can configure the font size. This is a best practice for accessibility (people with vision problems for example) – Quanturium Feb 23 '15 at 19:40
  • And it makes the game look ugly because on different devices text size doesnt fit image sizes and so on – Greyshack Feb 23 '15 at 19:53
0

If you insist on having the same looks on every device, you can manage some details on different devices. Look at webpage Display class and WindowManager. Here is a sample code that I have used for a certain UI element:

Display display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);

Good luck with this. It's not easy to manage all your graphics.

The Original Android
  • 6,147
  • 3
  • 26
  • 31
  • Nesting LinearLayouts with weights make it pretty simple for everything but the text size, that's the hardest part for me. I'll try this, thanks. – Greyshack Feb 24 '15 at 08:12