• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Portrait/Landscape issue

 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Dave MacLean
author
Ranch Hand
Posts: 49
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Satya Komatineni
author
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic