get Current Screen Width Px - Android Phone

Android examples for Phone:Screen

Description

get Current Screen Width Px

Demo Code


//package com.java2s;
import android.content.Context;
import android.graphics.Point;

import android.view.Display;
import android.view.WindowManager;

public class Main {
    public static int getCurrentScreenWidthPx(Context context) {
        Point size = new Point();
        getDefaultDisplay(context).getSize(size);
        return size.x;
    }//ww w  .j  a va  2  s.  co m

    private static Display getDefaultDisplay(Context context) {
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        return wm.getDefaultDisplay();
    }
}

Related Tutorials