Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android widget different portrait and landscape orientation

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!

like image 750
strange quark Avatar asked May 01 '10 23:05

strange quark


People also ask

How do I make different layouts portrait and landscape orientations?

Android App Development for Beginners Step 3 – Create a layout file by right-clicking on the resources, name the file, from the 'Available qualifiers, select Orientation. Click >> option. Select Landscape from UI mode.

How do I force horizontal orientation on Android?

When on the main screen, under the orientation section, you will see a number of options like 'Auto-rotate OFF', 'Auto-rotate ON', 'Forced Portrait' and 'Forced Landscape'. As the names suggest, you can use these buttons as one-tap shortcuts to toggle the orientation of your device.


1 Answers

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.

like image 106
CommonsWare Avatar answered Nov 11 '22 10:11

CommonsWare