//在调用contentView的layout()方法时,该监听器会被调用
contentView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
Log.e(MainActivity.this.getClass().getSimpleName(),"left: " + left + "; top: " + top);
}
});
//控件树的一次布局只会调用一次,而不是调用每个View的layout()方法都会调用
contentView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Log.e(MainActivity.this.getClass().getSimpleName(), "onGlobalLayout");
}
});
ViewTreeObserver的其他监听接口