get Screen Vertical Size - Android android.app

Android examples for android.app:Screen

Description

get Screen Vertical Size

Demo Code

import android.content.Context;
import android.view.ViewGroup;

public class Main {

  private static final int STANDARD_HEIGHT = 1280;

  @SuppressWarnings("deprecation")
  public static int getVerticalSize(Context context, int height) {
    if (height == ViewGroup.LayoutParams.MATCH_PARENT || height == ViewGroup.LayoutParams.WRAP_CONTENT) {
      return height;
    } else {//from   w  w  w .  j a  va2s  .c  o  m
      return (getDisplayHeight(context) * height) / STANDARD_HEIGHT;
    }
  }

  public static int getDisplayHeight(Context context) {
    return context.getResources().getDisplayMetrics().heightPixels;
  }

}

Related Tutorials