get Window Width - Android android.app

Android examples for android.app:Window

Description

get Window Width

Demo Code

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);/*from   www.  j av  a 2s. c om*/
        return dm.widthPixels;
    }

}

Related Tutorials