Possible Duplicate:
Activity restart on rotation Android
I've got a LinearLayout that I want to be android:orientation="vertical"
when in portrait mode, and android:orientation="horizontal"
when in landscape. The activity performs some complex operations, so allowing the activity to close and restart itself on an orientation change is not an option, so that rules out using the layout-land feature or anything else involving restarting the activity. I am currently programmatically setting the correct android:orientation
in activity's onStart
and onConfigurationChanged
.
Unfortunately, only about 20% of the time does it actually change the layout when you rotate the screen. I haven't been able to pick up on a pattern - it seems to do it sometimes, and other times it doesn't. I've tried calling .invalidate()
on the LinearLayout after performing the change, but that didn't seem to work. How can I force the view to redraw with the new orientation, or there some better way to accomplish this?
Basically, here's the code in question that works sometimes, but not others:
@Override
public void onConfigurationChanged(Configuration newConfig) {
((LinearLayout)contentView.findViewById(R.id.someLinearLayout))
.setOrientation(newConfig.orientation==Configuration.ORIENTATION_PORTRAIT ?
LinearLayout.VERTICAL
: LinearLayout.HORIZONTAL);
}