Android recommends to use Density-independent Pixel (dp) instead of Pixels in order to scale views based on the current screen density. In order to get the width and height of the android in "dp" units, you can use the following code.
This code is independent of the container view and could be used to calculate screen size and draw custom user interface.
. . Display display = getWindowManager().getDefaultDisplay(); DisplayMetrics outMetrics = new DisplayMetrics (); display.getMetrics(outMetrics); float density = getResources().getDisplayMetrics().density; float dpHeight = outMetrics.heightPixels / density; float dpWidth = outMetrics.widthPixels / density; . .
This code is independent of the container view and could be used to calculate screen size and draw custom user interface.
Nice post!
ReplyDeleteWhat I do first is to design with photoshop the elements of my app and then i resize the images with an app called Design for multiple densities
https://play.google.com/store/apps/details?id=com.useit.software.android.densityconverter
Worth to take a look!
Seems Link Broken
DeleteThanks
ReplyDelete