views:

153

answers:

1

Hi,

i have developed the android application screen resolution is 320x480 Px but i want to run same application without any code modification with Droid Mobile(480x854 px).

i have installed android application with droid mobile but it's displaying only half of the page in droid mobile( i am using the android 2.0 SDK device).

is there any way to resolve this kind of issues?

Regards, Jeyavel N

+1  A: 

Yes: Use density independent pixels (dip) instead of pixels (px) when specifying dimension and position of screen elements. That way, Android will automatically scale these values to different screen resolutions and pixel densities.

When having to specify these programatically, you may find this conversion method useful:

public static int dipToPx(Activity context, int dip) {
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    return (int) (dip * displayMetrics.density + 0.5f);
}

By just following that, and a little fine tuning, I was able to get our app running on all different screen sizes out there.

Matthias
Your technique is too complicated, why don't you just do context.getResources().getDisplayMetrics()? :)
Romain Guy
hey great, didn't know that. thanks!
Matthias