Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Layouts by screen size

 
Jacquie Beeler
Greenhorn
Posts: 3
Android Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys!

I am a beginner here, so please excuse my beginner questions.

I have several small apps that I am currently working on (a temperature converter, a calculator and a tic-tac-toe game). I currently test them on both the emulator and my Sony Tablet S (sadly, I don't have an Android phone to test on or I would use that as well). My question is this: how can I make the layouts fit the different screen sizes better? The layouts all look great on the Nexus One setting in the emulator. What should I do? (Sorry if my question isn't clear, I had trouble wording it.)


Thanks!
Jacquie a
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest case would be if it's just a matter of re-arranging the same layout elements in a different way, e.g. two buttons in one row on a wide screen instead of in two rows on a narrower screen. Android allows you to keep multiple versions of the same layout XML file for different screen characteristics. Right now you probably have all your layout files in the "layout" directory. But you can have more directories with exactly specified names, and if those contain layout files of the same name as in the "layout" directory, they will be used instead. For example, the files in "layout-land" will be used if a device is turned into landscape mode. For an app I'm working on I also have "layout-xlarge" and "layout-xlarge-land", which are the ones to be used for tablets. All this is described in a lot more detail in http://developer.android.com/guide/practices/screens_support.html

If that doesn't suffice you'll have to make changes in the code. For starters, this will tell you the current orientation:

 
Jacquie Beeler
Greenhorn
Posts: 3
Android Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! Now, once I have created the layouts for different screen sizes, what must I do next? Say, if I have a folder "layout-xlarge" or something like that with the larger screen size layout in it, what do I need to do to have that layout actually run in my app?

 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing. Android will automatically that use that layout instead of the one in "layout" for devices that qualify as "xlarge".
 
Jacquie Beeler
Greenhorn
Posts: 3
Android Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, okay! Very good. Thank you so much. https://www.google.com/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic