get Screen Width - Android User Interface

Android examples for User Interface:Screen Size

Description

get Screen Width

Demo Code


//package com.java2s;
import android.app.Activity;

import android.util.DisplayMetrics;

public class Main {
    public static int getScreenWidth(Activity activity) {
        DisplayMetrics dm = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
        return dm.widthPixels;
    }/*w  w  w.  j  av a2 s . c  om*/
}

Related Tutorials