Kraken
Kraken

Reputation: 24213

Landscape mode not changing the layout

So I've started learning android app development and I was going through the example. In my layout file, I have named the main activity as activity_sudoku.

I launched the app, and everything was ok, then I changed to landscape mode, and in the book it says that it should change to landscape, but although my emulator is in landscape mode, but my app is still in the same mode.

Here are the two screenshots

View 1

and

View 2

Now I created folder layout-land and copied the same file in there, but changed the text of one of the buttons. But it is still the same. What am I doing wrong?

Upvotes: 0

Views: 471

Answers (3)

Dharmaraj
Dharmaraj

Reputation: 1306

Add these line AndroidManifest.xml to your activity which you want to give orientation.

android:configChanges="orientation|keyboardHidden|screenSize"

In Code use these lines for orientation change

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Also keep in mind to set orientation after <"setContentView"> as

setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Upvotes: 0

Hamad
Hamad

Reputation: 5152

it was solved by disabling the "Hardware keyboard present" checkbox in the "Edit Android Virtual Device (AVD)" window in my case.

as other answers on stackoverflow suggest that it is a bug with the 2.3 emulator. http://code.google.com/p/android/issues/detail?id=13189

Upvotes: 1

Phant&#244;maxx
Phant&#244;maxx

Reputation: 38098

It's a well known bug of the emulator... (the 2.2 emulator seems to be the only one working also in landscape, changing orientation accordingly)

Upvotes: 1

Related Questions