• 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
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Android Recipes: Is there a topic to cover the different screen size?

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Authors,

I'm new to programming for mobile devices. I did a little web programming. It's difficult to get the application work on different screen size or resolution. Does programming for Android have the same problem? Will the same program work on various Android devices by different companies?

If the problems above do exist, what are your recipes to resolve them?
 
Author
Posts: 25
5
Android IntelliJ IDE Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Problem" may not be the right word to describe this, but device variance is an issue you need to consider when developing an Android application. Android runs on a wide variety of device hardware and along with that comes a handful of different screen size/resolution/aspect ratio combinations. I would say that the number of device screens to support does not even begin to match the number of Android devices on the market, most all devices (certainly those running Google Play) will fit into about 2-3 types for handsets and 2-3 types for tablets.

The native Android framework works very hard to provide you with the tools to develop your application's user interface in a way that will be flexible and scale to accomodate the different screens. The more you can utilize the resource framework Android provides to select appropriate layouts, images, dimensions, etc. that best fit different screen types, the less work supporting the Android ecosystem will become for you as a developer. This means, above all else, designing your UI in a flexible manner. Here are a few thoughts on this:

  • You can fix the size or position of an element, but not both.

  • It is okay to provide fixed assets in your UI (i.e. a button must be this size to fit the background I've created for it, or this element should always be 10dp from the top of the screen) but avoid trying to do both. If you must fix the size, allow the location to float appropriately so that extra space on larger screens is used appropriately.

  • Where possible, use scalable image assets

  • Creating a static image for a button background may not be the best approach if you want that button style to wrap the text you put in, as that background will stretch and skew in many cases. The Drawable class and 9-Patch graphics are your friend here that can allow you to create graphics in your application that are not dependent on a fixed pixel size.

  • Use scaled dimensions always

  • In the first point I mentioned "10dp", which is a scaled dimension unit Android provides. By using these values to declare fixed sizes/positions instead of direct pixel values, Android will do the work of making that dimension look correct based on the density of the device's screen.

    In response to your last question, there are several recipes in Chapter 2 that assist you in seeing how the resource system and flexible graphic assets can help you build a great native application that isn't dependent on any one device type.
     
    What's that smell? I think this tiny ad may have stepped in something.
    The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
    https://www.kickstarter.com/projects/paulwheaton/low-tech
    reply
      Bookmark Topic Watch Topic
    • New Topic