Could I force changing the view's orientation in order to test how the layout appears or it is not possible to test this behavior on virtual device.
Under forcing it, I mean for example on click event to change from one to another screen orientation and inverse.
Ctrl+F11
will switch the screen orientation, but when it come to coding the orientation to change you have a couple of options:
Activity
to be a given orientation. Which is useful when you want to force the user to use a specific orientation only.Activity
to allow either orientation and let the user decide.Each of these is useful in their own scenarios. For example, viewing a graph that will only be useful in landscape should be hardcoded, but scrolling through a list could allow a user to pick which was more comfortable for them.
How to set the mode:
Activity
you want to edit and set the Screen Orientation
directly.AndroidManifest.xml
:
<activity android:screenOrientation="[fill in preference here]" />
Activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_[type])
Activity.getRequestedOrientation()
An explanation of the different modes can be found here: Screen Orientation Types | Activity
So, if you want to force a change on a screen based on user input, you can all you need to do is set the orientation type in code.