get Display Metrics via Context - Android android.content

Android examples for android.content:Context

Description

get Display Metrics via Context

Demo Code

import android.content.Context;
import android.text.TextUtils;
import android.widget.TextView;

public class Main{

    public static int getDisplayMetrics(Context context, int tp) {
        int pixels = 0;
        if (tp == 0) {
            pixels = context.getResources().getDisplayMetrics().widthPixels;
        } else if (tp == 1) {
            pixels = context.getResources().getDisplayMetrics().heightPixels;
        }// w  w  w. j a  va  2s. c o  m
        return pixels;
    }

}

Related Tutorials