Saturday, December 15, 2012

Android Screen Size Example


GET SCREEN SIZE 

SOURCE CODE is

package com.ScreenSizeExample;

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

public class ScreenSizeExample extends Activity
{
                public void onCreate(Bundle savedInstanceState)
{
 super.onCreate(savedInstanceState);
                                setContentView(R.layout.main);
       
                                 int height,width;

DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
       
                                height = displaymetrics.heightPixels;
                                width = displaymetrics.widthPixels;
       
                                Toast msg = Toast.makeText(ScreenSizeExample.this,
                                                "HEIGHT : "+height+"\nWIDTH : "+width, Toast.LENGTH_LONG);
                                msg.show();
}
}




The OUTPUT will be

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzYrecqFyT6LSXnfsMX4pzIqBh5UjF0occzpz9OfdjkDtDfyn0PNroU830Sv51cbVIVnlFo1p0GRqJYk2kagXDeQ5VrjSgGcEymwROFSa-F0qEEXoYIJtuJqj4edt0_409-3Sqe75n_Bw/