2

I'm developing an android app for phones and tablets.

I want all of the devices to use portrait layout. I made a 'layout' folder for it. But, there are some X number of devices which are always in landscape mode. Probably, large tablets. So, I made a 'layout-land' folder too.

Which folder I need to add so that X amount devices will always display landscape layout only, while other devices will always display portrait layout?

Main requirement is to have only portrait layouts displayed. But, display Landscape layout when device itself is in landscape mode(default). I am talking about devices that display drawer in landscape mode, and the ones that open landscape layout of apps only.

Is this automatic?

I have android:screenOrientation="portrait" in manifest. I can't test this as I don't have a tablet/large device.

I have already looked at this question and other similar questions.

Community
  • 1
  • 1
rupinderjeet
  • 2,984
  • 30
  • 54
  • did you try this setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); in your onCreate() method before setContentView() method – Raju Nov 14 '16 at 07:13
  • Why not to test it on tablet emulator? Android Studio 2.2 has advanced emulators that will allow you to analyze your problem – Marat Nov 14 '16 at 07:22
  • @Marat I had this problem like 10-12 days ago. I am used to write down problems that occur in between and then, solve them separately. Today, I wanted to sort it out. But, strangely, Android Studio's Preview started displaying all layouts in portrait. Be it a 10.1" tablet or 3.7" phone. Back when i didn't have 'layout-land' folder, some tablets like PixelC, Nexus7, Nexus9 were being displayed as landscape(forcing portrait layout in landscape). Now, it is gone, somehow. I can't reproduce the problem somehow. But, i don't know about how a live device would act. – rupinderjeet Nov 14 '16 at 07:25
  • In my question, X is a device which is landscape by default. X is not a number of these devices. – rupinderjeet Nov 14 '16 at 08:17

1 Answers1

0

Add the below line in your onCreate() method before setContentView()

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORT‌​RAIT);
Raju
  • 1,183
  • 3
  • 11
  • 19
  • problem is that i don't have a device to test this on. Are you sure this works? Also, Will it set landscape layout for a device that is landscape by default? Can you test it? – rupinderjeet Nov 14 '16 at 07:20
  • yes we are using it, for tablet device by default landscape use setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); – Raju Nov 14 '16 at 07:24
  • How would you know that device is a portrait/landscape device by default? My app doesn't have flavors. Its same package for phones and tablets. – rupinderjeet Nov 14 '16 at 08:14