Android widget different portrait and landscape orientation

strange quark picture strange quark · May 2, 2010 · Viewed 7.6k times · Source

I have a (hopefully) a relatively simple question. How do I tell Android which layout to use for portrait and which layout to use for landscape orientation on my AppWidget?

Thanks in advance!

Answer

CommonsWare picture CommonsWare · May 2, 2010

First, bear in mind that some home screens (e.g., Nexus One) do not change orientation.

The standard approach for having different layouts per orientation is to put the portrait version in res/layout/, and the landscape version in res/layout-land/, both under the same name (e.g., appwidget.xml). Then, just refer to it by name (e.g., R.layout.appwidget), and Android will choose the file based on the orientation. This definitely works for activities, so I would assume it works for app widgets, but I don't think I have actually tried it.