How to get the available screen height minus the navigation bar in HoneyComb?

Is there a way to measure the height of the navigation bar below in pixels?

+8
android android-3.0-honeycomb
source share
2 answers

Meanwhile, I found a solution. honycomb has a new OnLayoutChangeListener event that allows you to wait for the layout to finish, and then measure the size of your layout instead of the screen.

+4
source share

By the way ... for someone like me who stumbled upon this question looking for the actual number, it's 48 pixels (at least with Motorola Xoom). This was based on debugging results of this (admittedly raw) test activity combined with an untitled theme (like @android: style / Theme.NoTitleBar) and a single-line LinearLayout with the same height and width, match_parent "(like created when creating a new Android application):

 package com.sample.layouttest; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnLayoutChangeListener; public class Main extends Activity implements OnLayoutChangeListener { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); View newView = getLayoutInflater().inflate(R.layout.main, null); newView.addOnLayoutChangeListener(this); setContentView(newView); } @Override public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { Log.d("LayoutTest","left="+left+", top="+top+", right="+right+", bottom="+bottom); } } 

In Motorola Xoom running Android 3.1 (as well as Samsung Galaxy 10.1V running 3.0), exit the onLayoutChange method when entering portrait mode:

 05-24 15:11:43.047: DEBUG/LayoutTest(8658): left=0, top=0, right=800, bottom=1232 

and when entering the album:

 05-24 15:13:18.837: DEBUG/LayoutTest(8658): left=0, top=0, right=1280, bottom=752 
+6
source share

All Articles