Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top