get Window Width - Android User Interface

Android examples for User Interface:Window

Description

get Window Width

Demo Code


//package com.java2s;
import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;

public class Main {

    public static int getWindowWidth(Context context) {
        DisplayMetrics dm = new DisplayMetrics();
        ((Activity) context).getWindowManager().getDefaultDisplay()
                .getMetrics(dm);/* www  .j  a v  a 2s .c om*/
        return dm.widthPixels;
    }
}

Related Tutorials