@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { int childLeft = 0; int childTop = 0; int childRight = right - left; int childBottom = bottom - top; boolean isPortrait = getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; if(isPortrait) childTop += mHeaderPrimaryRealHeight + mHeaderSecondaryHeight; else childLeft += mHeaderRealWidth; mDatePicker.layout(childLeft, childTop, childRight, childBottom); childTop = (childBottom + childTop - mYearPicker.getMeasuredHeight()) / 2; mYearPicker.layout(childLeft, childTop, childRight, childTop + mYearPicker.getMeasuredHeight()); }