0

To explain - here is an example.

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
myButton.setTextSize((float)metrics.widthPixels / 10f);

Problem is, on Galaxy J5 and most other phones I've tested, the resulting text size is correct - 1/10th of the width of the screen. On Galaxy A5 and Huawei P9 Lite it is not (it's larger). What could be the problem? Am I missing something?

  • what does it show on A5? – Vladyslav Matviienko Apr 05 '18 at 08:42
  • Just a hunch, but `setTextSize()` takes `sp` (scalable points) as the parameter, so depending on font scaling they can be interpreted in different ways. [This question/answer seems relevant.](https://stackoverflow.com/questions/3687065/textview-settextsize-behaves-abnormally-how-to-set-text-size-of-textview-dynam) – Markus Kauppinen Apr 06 '18 at 15:01

0 Answers0