Thursday, March 21, 2013

Android: Get screen width programmatically example

It returns number in pixel





      @SuppressLint("NewApi")
      private int getScreenWidth() {
            int iMeasuredwidth = 0;
            Point size = new Point();
            WindowManager w = getWindowManager();
            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2){
                  w.getDefaultDisplay().getSize(size);
                  iMeasuredwidth = size.x;
            }else{
                  Display d = w.getDefaultDisplay();
                  iMeasuredwidth = d.getWidth();
            }
            return iMeasuredwidth;
      }


No comments:

Post a Comment