How to get the available Screen Height minus Navigation Bar in HoneyComb?

只愿长相守 提交于 2019-12-18 16:19:13

问题


Is there a way the measure the hight of the navigation bar at the bottom in pixels?


回答1:


By the way... for anyone else like me who stumbled upon this question looking for the actual number, it's 48 pixels (on the Motorola Xoom, at least). This was based upon the debug output of this (admittedly crude) test Activity, combined with a Theme with no title bar (e.g., @android:style/Theme.NoTitleBar) and a single-View LinearLayout with both height and width set to "match_parent" (e.g., the one created when creating a new Android app) :

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);
    }
}

On a Motorola Xoom running Android 3.1 (as well as a Samsung Galaxy 10.1V running 3.0), the output from the onLayoutChange method when entering portrait mode is :

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

and when entering landscape :

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



回答2:


meanwhile i found the solution. there is a new OnLayoutChangeListener event in honycomb wich allows you wait for the layout to be finished and then measure the size of your layout instead of the screensize.



来源:https://stackoverflow.com/questions/5116648/how-to-get-the-available-screen-height-minus-navigation-bar-in-honeycomb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!