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!
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With