Hai friends My name is arunkumar and I'm working as an android developer.I'm gonna blog my journey through android world right here...I hope it will be helpful for anyone who's in the same journey...and i also want you to help me to improve the quality of this blog if you are an experienced Android developer...
Friday, August 17, 2012
Android DisplayMetrics
Get screen resolution using android.util.DisplayMetrics
android.util.DisplayMetrics is a structure describing general information about a display, such as its size, density, and font scaling.
To use android.util.DisplayMetrics to get resolution:
Create a dummy Android Application, add a TextView in main.xml to display the result.
<TextView
android:id="@+id/strScreenSize"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
Modify the .java file to read DisplayMetrics
package com.exercise.AndroidScreen;
import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.widget.TextView;
public class AndroidScreenActivity 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 str_ScreenSize = "The Android Screen is: "
+ dm.widthPixels
+ " x "
+ dm.heightPixels;
TextView mScreenSize = (TextView) findViewById(R.id.strScreenSize);
mScreenSize.setText(str_ScreenSize);
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment