nenito
nenito

Reputation: 1284

Could I force switching portrait/landscape view on emulator?

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.

Upvotes: 2

Views: 1387

Answers (3)

gtcompscientist
gtcompscientist

Reputation: 681

Ctrl+F11 will switch the screen orientation, but when it come to coding the orientation to change you have a couple of options:

  • Hardcode the Activity to be a given orientation. Which is useful when you want to force the user to use a specific orientation only.
  • Set the 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:

  • In Eclipse go to the AndroidManifest->Application Tab, Select the Activity you want to edit and set the Screen Orientation directly.
  • In AndroidManifest.xml: <activity android:screenOrientation="[fill in preference here]" />
  • In code: Activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_[type])
  • To get the current orientation in code:
    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.

Upvotes: 3

Andro Selva
Andro Selva

Reputation: 54322

Did you try Ctrl+F11 keyboard shortcut or as the user dragon112 has suggested you can go for numpad key "7" with numlock "on".

Upvotes: 2

Manuel
Manuel

Reputation: 10303

This is done with the HOME(7) button on the num pad (num lock needs to be disabled i beleve, not sure tho).

Upvotes: 2

Related Questions