8

有没有办法测量底部导航栏的高度(以像素为单位)?

4

2 回答 2

6

顺便说一句......对于像我这样偶然发现这个问题以寻找实际数字的其他人来说,它是 48 像素(至少在摩托罗拉 Xoom 上)。这是基于这个(诚然粗略的)测试活动的调试输出,结合了一个没有标题栏的主题(例如,@android:style/Theme.NoTitleBar)和一个高度和宽度都设置为“ match_parent”(例如,在创建新的 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 的摩托罗拉 Xoom(以及运行 3.0 的三星 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
于 2011-04-15T17:40:34.697 回答
4

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

于 2011-03-11T12:42:35.047 回答