废话不说了 直接上代码:
public boolean hasMeasured = false;
//下面是主要实现 放在oncreate函数下就可以了
container = (FrameLayout) findViewById(android.R.id.tabcontent);
ViewTreeObserver vto = container.getViewTreeObserver();
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
public boolean onPreDraw() {
if (hasMeasured == false) {
int height = container.getMeasuredHeight();
int width = container.getMeasuredWidth();
hasMeasured = true;
//LOG一下或者TOAST一下就可以了
}
return true;
}
});