Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Height of screen without status bar, actionBar and tabs

I have a ListView that I want each row to fill a third of the available screen. I have the status bar visible, and then an actionBar with slidingTabs beneath. I'm doing the current calculation like this:

height = context.getResources().getDisplayMetrics().heightPixels;
if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
    {
        actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,context.getResources().getDisplayMetrics());
        Log.d("actionBarHeigth", actionBarHeight.toString());
    }

And setting the views height like this:

holder.imageView.getLayoutParams().height = (height - actionBarHeight*2) / 3;

But the rows of the list are slightly too big, and i guess it's the status bar causing it. How can I add the height of it to my calculations?

like image 541
Kæmpe Klunker Avatar asked Apr 17 '15 10:04

Kæmpe Klunker


People also ask

How can I change Actionbar height in Android?

This example demonstrates how to change action bar size in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 3 − Add the following code to res/layout/activity_main. xml.

What is the height of Status Bar Android?

What is the size of status bar? Official height is 24dp , as is stated officially by Google on Android Design webpage. Save this answer.

What is the standard app bar toolbar height?

The Toolbar (if not extended) has the height of: 56dp (default)


1 Answers

Based on @rasmeta 's answer I made this code and it does the trick. My rows are now exactly a third of the available screen. Here is how to get the height of the status bar:

int resource = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resource > 0) {
        statusBarHeight = context.getResources().getDimensionPixelSize(resource);
    }

And the calculation of the height of each row goes like this:

holder.imageView.getLayoutParams().height = (screenHeight - statusBarHeight - actionBarHeight*2) / 3;
// actionBarHeight * 2 because the tabs have the same height as the actionBar.
like image 156
Kæmpe Klunker Avatar answered Oct 10 '22 13:10

Kæmpe Klunker