final FrameLayout layout =(FrameLayout)findViewById(R.id.main_view);
ViewTreeObserver vto = layout.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
public void onGlobalLayout() {
layout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
XMAX = layout.getMeasuredWidth();
YMAX = layout.getMeasuredHeight();
System.out.println("==== The Y Max Is : " + (YMAX));
}
});
答案 0 :(得分:-1)
使用getWidth()
和getHeight()
。视图已经具有宽度和高度,因为在调用该侦听器时它已通过布局传递。