1

I've asked a question similar to this but thought I would ask a more general question to get a wider range of input.

I ask this question because the last two apps I've developed, I threw all image resources in the drawable-hdpi folder, didn't deal with landscape-mode, tested it mainly on my own personal Droid phone, and basically felt like I was only developing for my own device. Although I did always use dpi and sp in the appropriate places, this was not enough for my app to scale appropriately on other screen sizes/densities. It scaled okay sometimes, but would always tend to cut off a portion of the screen on smaller sizes.

What are the best ways to begin an app that will scale at least somewhat well on all devices?

For example, should I construct my app layouts so that it looks correct on the default HVGA screen and allow it to scale to larger densities? Would it be a best practice to be actively building both portrait and landscape layout files?

What are you doing to ensure your apps look nice on all devices without just focusing on one size and then scrambling around later to manage this?

joepetrakovich
  • 1,344
  • 3
  • 24
  • 42

1 Answers1

2

I always follow those rules:

  • set everything from supports-screens to true. Android will know that you are ready for every screen environment and you will know that it doesn't make any screen virtualization. For example: even if your device has big-size screen, your code will see it as a normal-size screen
  • don't use fixed sizes for width and height. If you must, use "dp" as a virtual pixel. use WRAP_CONTENT and FILL_PARENT. "dp" is a physical pixel on screen with 160 dpi. If your app runs on device with lower/higher density, android will recalculate this for you.
  • use "dp" as a unit for font size.
  • try to do everything relatively. U can use RelativeLayout if you want to have "something under another" etc. If you need percentages you can use LinearLayout.
  • use nine-pathes as a background.
  • make sure that you put resources into correct drawable/layout folders.

Off-course, this is not best approach for every project :) Sometimes UI designer wants some extra :]

Damian Kołakowski
  • 2,731
  • 22
  • 25
  • Could you discuss "don't use fixed sizes for width and height." a little further? What should be used in place of hard-coding a width or height of something? – joepetrakovich Dec 09 '10 at 01:22
  • the supports-screens attributes default to true so there is no point in setting them all to true – pheelicks Dec 09 '10 at 01:26
  • I stand corrected. Details of differences between API versions can be found here: http://developer.android.com/guide/practices/screens_support.html#attrs – pheelicks Dec 09 '10 at 07:27
  • 1
    ...and there is default "false" for "minSdkVersion or targetSdkVersion is 4 or lowe" – Damian Kołakowski Dec 09 '10 at 08:30