Android Convert Px to Dp (Video Aspect Ratio) [duplicate]

Instead of trying to infer the dp conversion factor from the screen’s density classification, you can simply query it directly: getWindowManager().getDefaultDisplay().getMetrics(metrics); float logicalDensity = metrics.density; logicalDensity will then contain the factor you need to multiply dp by to get physical pixel dimensions for the device screen. int px = (int) Math.ceil(dp * logicalDensity);

How to get the screen DPI in java?

The problem is no one, not even the OS, knows the exact physical dimensions of the screen. You’d need to know that in order to calculate the PPI. There’s a display setting in the control panel where the user can manually specify the PPI and by default it’s set to 96.

How to support all the different resolutions of android products

You don’t have to do that to support different densities. What you do is create different resources folders: res/values-ldpi/dimens.xml res/values-mdpi/dimens.xml res/values-hdpi/dimens.xml Then Android will decide which file to use. You can have something like: <!– in values-ldpi/dimens.xml –> <dimen name=”textSize”>25dip</dimen> and.. <!– in values-mdpi/dimens.xml –> <dimen name=”textSize”>20dip</dimen> etc. And you shouldn’t care about resolution… there … Read more

Android supporting multiple resolution with multiple layout folder

For Different screen size, The following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for small, medium, high, and extra high density screens. res/layout/my_layout.xml // layout for normal screen size (“default”) res/layout-small/my_layout.xml // layout for small screen size res/layout-large/my_layout.xml // layout … Read more

How to accommodate for the iPhone 4 screen resolution?

According to Supporting High-Resolution Screens In Views, from the Apple docs: On devices with high-resolution screens, the imageNamed:, imageWithContentsOfFile:, and initWithContentsOfFile: methods automatically looks for a version of the requested image with the @2x modifier in its name. It if finds one, it loads that image instead. If you do not provide a high-resolution version … Read more