如何在HoneyComb中获取可用屏幕高度减去导航栏的高度?

8

有没有一种方法可以以像素为单位测量底部导航栏的高度?

2个回答

6
顺便提一下... 对于像我这样的其他人,他们在寻找实际数字的时候,至少在Motorola Xoom上是48像素。这是基于此(诚然粗糙)测试Activity的调试输出,结合没有标题栏的主题(例如@android:style/Theme.NoTitleBar)和一个高度和宽度都设置为"match_parent"的单个View LinearLayout(例如创建新Android应用程序时创建的那个)。
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);
    }
}

在运行Android 3.1的Motorola Xoom(以及运行3.0的Samsung Galaxy 10.1V)中,当进入纵向模式时,onLayoutChange方法的输出为:
05-24 15:11:43.047: DEBUG/LayoutTest(8658): left=0, top=0, right=800, bottom=1232

进入横屏模式时:

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

4

同时我找到了解决方案。在Honycomb中有一个新的OnLayoutChangeListener事件,它允许您等待布局完成,然后测量您的布局的大小,而不是屏幕大小。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接