2

I have an issue.

I have a method which checks if screen is in landscape mode:

private boolean isLandscape() {
    final Resources resources = getResources();

    return resources != null && resources.getConfiguration() != null
            && resources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
}

It works perfectly when screen is not split. The problem is the next:

It returns false when screen is split. In this case resources.getConfiguration().orientation returns ORIENTATION_PORTRAIT. I have read android reference(#1, #2), but I did not found any information.

  • Device: Nexus 5x
  • OS: Android 7.0

Any suggestions?

Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
  • 2
    Gone through this link ? https://medium.com/google-developers/5-tips-for-preparing-for-multi-window-in-android-n-7bed803dda64#.tiw9in4e6 – Sreehari Sep 28 '16 at 08:15
  • @Stallion no. There is important phrase: >Multi-window takes advantage of the resource system by adjusting the configuration based on the size of your window — screen size is the obvious one, but the smallest width (i.e., the minimum of the width or height) and the orientation are also updated when resizing. – Andrii Abramov Sep 28 '16 at 08:18
  • @Stallion it helped me. I understood the source of problem. – Andrii Abramov Sep 28 '16 at 08:26
  • Cheers, happy coding – Sreehari Sep 28 '16 at 09:48

1 Answers1

0

Thankfully to the link provided by Stallion, I found the reason:

Turns out: “portrait” really just means the height is greater than the width and “landscape” means the width is greater than the height. So it certainly makes sense, with that definition in mind, that your app could transition from one to the other while being resized.

See this link for more information.

Community
  • 1
  • 1
Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96