Android Screen Size Get getScreenSize(Activity ctx)

Here you can find the source of getScreenSize(Activity ctx)

Description

get Screen Size

License

Apache License

Declaration

public final static int[] getScreenSize(Activity ctx) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import android.app.Activity;

import android.content.Context;

import android.util.DisplayMetrics;

public class Main {
    public final static int[] getScreenSize(Context ctx) {
        int[] screenSize = new int[2];
        try {/*from   ww w. j av a  2s.  co  m*/
            DisplayMetrics displayMetrics = ctx.getResources()
                    .getDisplayMetrics();
            screenSize[0] = displayMetrics.widthPixels < displayMetrics.heightPixels ? displayMetrics.widthPixels
                    : displayMetrics.heightPixels;
            screenSize[1] = displayMetrics.widthPixels > displayMetrics.heightPixels ? displayMetrics.widthPixels
                    : displayMetrics.heightPixels;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return screenSize;
    }

    public final static int[] getScreenSize(Activity ctx) {
        int[] screenSize = new int[2];
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ctx.getWindowManager().getDefaultDisplay()
                .getMetrics(displayMetrics);
        screenSize[0] = displayMetrics.widthPixels;
        screenSize[1] = displayMetrics.heightPixels;
        return screenSize;
    }
}

Related

  1. getRealScreenDimensions(Context context)
  2. getScreenHeight(Context context)
  3. getScreenSize(@Nonnull Context context)
  4. getScreenWidth(Context context)
  5. getScreenDensity(Context context)
  6. getScreenSize(Context context)
  7. getScreenSize(Context ctx)
  8. getMinTouchHeight(Context context)
  9. getMinTouchWidth(Context context)