Question

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?

Was it helpful?

Solution

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 :]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top