I have an Activity which handles orientation change and I want to manually resize a layout when the device is rotated. In the onLayout of that layout, I call setLayoutParams:
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (changed) {
int orientation = getResources().getConfiguration().orientation;
// Only resize on actual orientation change
if (orientation != mLastOrientation) {
// Apply the new layout size
setLayoutParams(new LinearLayout.LayoutParams(someNewWidth, someNewHeight);
mLastOrientation = orientation;
}
}
}
This works fine on my newer 4.x devices but on the 2.x devices, the setLayoutParams appears to run one orientation "late".
So on the first rotation from portrait to landscape, the resize does not occur, then on subsequent rotations it shows my landscape size on portrait, portrait size on landscape, and so on.
I read in the setLayoutParams source that it calls requestLayout which is supposed to redraw the layout, but doesn't appear to be doing this immediately. I have also tried invalidate() which does not work either.
Any ideas on why setLayoutParams is not applying on the first rotation, or alternative solutions?