有没有一种方法可以测量底部导航栏的高度(以像素为单位)?
最佳答案
顺便说一下...对于像我这样偶然发现这个问题的其他人,寻找实际数字,它是48像素(至少在Motorola Xoom上)。这是基于此测试 Activity (当然是粗略的)的调试输出,结合了没有标题栏的主题(例如@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的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