This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • 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?
 
D. Smith
Author
Greenhorn
Posts: 25
5
Android IntelliJ IDE Objective C
  • Mark post as helpful
  • send pies
  • 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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic