• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

Portrait/Landscape issue

 
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
author
Posts: 51
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic