get Current Screen Width Pixel - Android User Interface

Android examples for User Interface:Screen Size

Description

get Current Screen Width Pixel

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;
    }/*from   w  ww.j a  v  a  2  s . co m*/

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

Related Tutorials