开发者

How to match android application with droid mobile?

开发者 https://www.devze.com 2022-12-19 23:53 出处:网络
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 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 an开发者_StackOverflow社区y way to resolve this kind of issues?

Regards, Jeyavel N


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消