有没有一种方法可以以像素为单位测量底部导航栏的高度?
有没有一种方法可以以像素为单位测量底部导航栏的高度?
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);
}
}
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
同时我找到了解决方案。在Honycomb中有一个新的OnLayoutChangeListener
事件,它允许您等待布局完成,然后测量您的布局的大小,而不是屏幕大小。