-1

I'm writing an app that I want it to work with different screen sizes.

While in portrait mode I divide the screen height by 5 in order to set it the result as the height for text views. Hence no matter what screen there should allways be five textviews.

I have a tablet with a 1280 pixel height, which display metrics height returns as 1232. In my phone with 1980, display metrics height shows 1776. These are the values that I divide by 5.

I see the 5 textviews in my tablet perfectly but in my phone the lasts textview is almost entirely off the screen. So my question is what is the height that is returned?

Charles
  • 50,943
  • 13
  • 104
  • 142
aarelovich
  • 5,140
  • 11
  • 55
  • 106

2 Answers2

3

That height returned is the screen height, minus the height of the notification bar. But you still have things like the action bar taking space.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • Seems about right. I found codes to calculate the action bar and Navigation Bar height and substracted them from the height and that was enough to fix my problem. Thank you! – aarelovich Mar 29 '14 at 17:55
1

Instead of dividing and do all the complicate math...

If you use a LinearLayout, you can set the weights of your TextViews to fit the screen nicely.
Just set all their weights to 1 and their height to 0dp.

So, if tou have 4 TextViews, they will be as tall as the 25% of the usable height.
If you have 5 (which is your case), they will be as tall as the 20% of the usable height.

And you'll avoid headaches.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • I can't my layout is completely defined programatically, because it is dynamic and it is much more complicated than that. I simplified the problem because that was the core of my problem – aarelovich Mar 29 '14 at 17:40
  • It is possible to do that programmatically: [http://stackoverflow.com/a/6073437/2649012](http://stackoverflow.com/a/6073437/2649012) – Phantômaxx Mar 29 '14 at 17:48