Android Screen Size Example - ANDROID - Helper

Tuesday, March 08, 2011

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/AVvXsEgi6y0Jpl2k3D4xg_k7PSAu4X5tiNthDlwANaz7yYvCjTFBUXPN9uMI62lPcfVaeoyxANqF5_QtJ2szkKP1HHXPgSUv-p3zN2fgOz8R0-HvimcNDdcN7HVObDdJjCKK1P6Zi9twdLvYF2g/

No comments:

Post a Comment