Dealing with different screen resolutions

June 3, 2010 at 5:26 pm | Posted in Uncategorized | Leave a comment

In android programming, what most of the developers often miss out is thinking about  the screen resolution. Most often applications are developed without taking into consideration the density or size and width of the device. This approach is fine till we are dealing with a single device.  But once your app is in the market , its obvious that people wont be having the same device. Also you cant restrain them on buying only a fixed kind of device. So what to do in such a situation :

Emulators of different resolutions

 In order to test for different screen resolutions, we will create three emulators of different sizes. If you are using Eclipse IDE, then follow these steps:

Go to Window –> Android SDK and AVD Manager –> Create AVD –> Choose the target and select resolution as 320 by 480.

Create another avd device of size 480 by 600 and third avd device of size 600 by 800.

Now we have our three emulators ready , we can test the same application on these emulators.

Now we will see how we can write an efficient program which will appear the same on all the emulators. Lets follow these steps:

  • While designing for the UI , all our widgets are created in the xml. Avoid giving padding in pixels. Also avoid giving fixed dimensions i.e setting the layout_width and height to rigid values(15px etc). These values will make the layout look differently when tested on different devices. The solution to this is that we must use dip padding wherever necessary. dip means density independent. Hence the widgets with dip dimensions will get adjusted on all devices.
  • Next try to give dimensions, use wrap_content and fill_parent at most of the places.
  • Avoid using RelativeLayout.  Creating xml using Linear and TableLayout is a good practice.

Once this compatible layout is ready, start testing it on the three created emulators.

All the best !

Leave a Comment »

RSS feed for comments on this post. TrackBack URI

Leave a comment

Create a free website or blog at WordPress.com.
Entries and comments feeds.