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

not*_*tme 8 android android-3.0-honeycomb

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

Mar*_*ark 6

顺便说一下......对于像我这样偶然发现这个问题寻找实际数字的人来说,这是48像素(至少在Motorola Xoom上).这是基于此(通常是粗略的)测试活动的调试输出,结合没有标题栏的主题(例如,@ android:style/Theme.NoTitleBar)和单一视图LinearLayout,其高度和宽度都设置为" 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);
    }
}
Run Code Online (Sandbox Code Playgroud)

在运行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
Run Code Online (Sandbox Code Playgroud)

进入景观时:

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


not*_*tme 4

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