IntelliJ Java IDE
The moose likes Android and the fly likes Portrait/Landscape issue Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Mobile » Android
Reply Bookmark "Portrait/Landscape issue" Watch "Portrait/Landscape issue" New topic
Author

Portrait/Landscape issue

Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1578
Hello,

I am new to Android development.

I have made a small application. when I rotate my phone from portrait to landscape mode, the elements of the activities are being displayed in a strange order. Some components are not being displayed at all. What shall I do to make sure when the mode it landscape all components appear properly?

Thanks in advance,


Vassili ...
SCJP 5.0, SCWCD 1.4, SCJA 1.0
Dave MacLean
author
Ranch Hand

Joined: May 10, 2011
Posts: 46

It all depends on how you defined the layout of your elements. The usual way is to create a layout XML file under the project's /res/layout directory. This is the folder where the default layouts go. To specify an alternate layout for the landscape configuration, add a layout XML file with the same filename to the /res/layout-land directory. Use the same element names for the landscape layout file. That way your code can look exactly the same but the layouts can be whatever you want them to be. My guess is that in landscape mode, some of your elements are off-screen because of the way the layout is defined. You won't automatically get a scrollbar; you may need to add one. While it is possible to learn Android without a book, I recommend you consider it at least. We cover controls and layouts in great detail in our book Pro Android 3.

- dave

Dave MacLean our book (Pro Android 3)
Satya Komatineni
author
Ranch Hand

Joined: May 11, 2011
Posts: 38
Rotating a phone is a fairly complex matter in Android.

Everything that Dave stated is true interms of resources and is probably the cause of layout discrepancy.

However one also needs to worry about the fact that Android closes and restarts the activity. Mind you that the process is not restarted but just the Activity instance.

So you need to use the save/restore instance methods to save your transient data and reestablish it. This happens not only for rotation of the device but any device configuration change such as connecting to a usb port or connecting an external monitor etc.

See if the following URL is use ful

Understand Android Configuration Changes


My Web Site: satyakomatineni.com
Our Book for Tablets/Phones: Pro Android 3
 
 
subject: Portrait/Landscape issue
 
Threads others viewed
Print in LANDSCAPE orientation ????
Change the Printer Orientation??
change print settings through javascript
HoneyComb 3.0 Orientation Issues
DeterminingText Orientation
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture