Android examples for Phone:Screen
get Screen Width
//package com.java2s; import android.app.Activity; import android.content.Context; import android.util.DisplayMetrics; public class Main { public static int getScreenWidth(Context context) { return getScreenSize(context)[0]; }/*w w w.ja va 2s.c o m*/ public static int[] getScreenSize(Context context) { DisplayMetrics displayMetrics = new DisplayMetrics(); ((Activity) (context)).getWindowManager().getDefaultDisplay() .getMetrics(displayMetrics); return getScreenSize(displayMetrics); } public static int[] getScreenSize(DisplayMetrics displayMetrics) { int[] screenSizeArr = new int[2]; screenSizeArr[0] = displayMetrics.widthPixels; screenSizeArr[1] = displayMetrics.heightPixels; return screenSizeArr; } }