Bart Friederichs Bart Friederichs - 7 months ago 40
Android Question

Have a fixed orientation based on screen size

I have an Android app built on a phone that I am going to update now to also support tablet-sized screens (in particular Galaxy Tab 10.1). I figured out the whole

thing, so that's fine. However, I built my app to have a fixed screen orientation in
, set as

Now, I want to have the following: have a fixed orientation for each screen size, the one fixed in portrait (layout-small) and the other as landscape.

doesn't do what I want, because it still switches from portrait to landscape and back. Worse even, the app crashes when I rotate my phone to landscape, because the
doesn't exist.

Can I do this by just defining XML files, or do I have to add code?


Instead of fixing the orientation on the manifest, you could use setRequestedOrientation. On the onCreate method of each activity, check if you are on a tablet or smartphone and set the desired orientation.

Another option could be Creating Multiple APKs for Different Screen Sizes, depending on your needs.