I have an activity who’s orientation is locked to portrait:
<activity android:name="MainActivity" android:label="@string/app_name"
android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar">
However within the activity i have a few custom views in which I draw some text, rectangles and notably, a Path representing an arrow.
I need to be able to update the arrow when the phone is rotated, without changing the overall layout of the activity.
so the activity and layout is always portrait, but my nested views need to be notified and re-drawn when the phone is tilted from portrait to landscape.
How can I listen for the change in physical orientation and update tell my nested views to redraw?
thanks, p
UPDATE:
It looks like there is no way to detect orientation change when current active
ActivityhasscreenOrientationset toportraitorlandscape(haven’t tested other values though. Even using broadcast receiver and ACTION_CONFIGURATION_CHANGED.The only way I can think of, is to manually track sensors.
This is not working:
You should override
onConfigurationChanged()function in yourActivityand refresh your UI from that function.Note that you need to add
android:configChanges="orientation"to you activity in order for this function to be called.