Loading

Saturday, July 9, 2011

Get screen size in DPI

android.util.DisplayMetrics is a structure describing general information about a display, such as its size, density, and font scaling.

Get screen size in DPI

package com.exercise.AndroidDPI;

import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.widget.TextView;

public class AndroidDPIActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);

String strScreenDIP = "";
strScreenDIP += "The logical density of the display: " + dm.density + "\n";
strScreenDIP += "The screen density expressed as dots-per-inch: " + dm.densityDpi +"\n";
strScreenDIP += "The absolute height of the display in pixels: " + dm.heightPixels +"\n";
strScreenDIP += "The absolute width of the display in pixels: " + dm.widthPixels + "\n";
strScreenDIP += "A scaling factor for fonts displayed on the display: " + dm.scaledDensity + "\n";
strScreenDIP += "The exact physical pixels per inch of the screen in the X dimension: " + dm.xdpi + "\n";
strScreenDIP += "The exact physical pixels per inch of the screen in the Y dimension: " + dm.ydpi + "\n";

TextView textScreenDIP = (TextView)findViewById(R.id.strScreenDIP);
textScreenDIP.setText(strScreenDIP);
}
}

SHARE TWEET

Thank you for reading this article Get screen size in DPI With URL http://x-tutorials.blogspot.com/2011/07/get-screen-size-in-dpi.html. Also a time to read the other articles.

0 comments:

Write your comment for this article Get screen size in DPI above!