Question

I'm writing a custom layout that is depending its lay-outing on the orientation of the device. For this I use the following call:

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
  .....
}

When running this on a device, this works fine and I see my custom layout responding to the orientation changes.

I would also have the same working in my layout editor of my IDE (Eclipse or Android Studio). So that I can see both landscape and portrait correctly in my editor. When I try this somehow getResources().getConfiguration().orientation always has the value of 0 which is according to the documentation Configuration.ORIENTATION_UNDEFINED.

Is there maybe some other way to retrieve the orientation in general or just for the editor? Or is this just not supported by the Android developer tools?

Was it helpful?

Solution

This isn't possible; we use the device orientation to pick the best matching layout resource to render in the layout editor (similar to what happens at runtime), but we don't also push an orientation value into getResources().getConfiguration().orientation layoutlib, our rendering library which runs portions of view code. We probably should. Would you mind filing a bug for this at http://b.android.com with category Component-Tools?

OTHER TIPS

Found this similar link

Getting orientation of Android device

...hope it serves your purpose .

Tor Norbye (Android Tools) has responded that this is not possible at this moment and filled a bug to solve this. You can read his answer on Google+.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top