Java tutorial
//package com.java2s; import android.app.Activity; import android.util.DisplayMetrics; public class Main { public static int getDefaultPhotoWidth(Activity activity, int columnNum) { return (getWindowMetrics(activity).widthPixels - (columnNum - 1) * 2) / columnNum; } public static DisplayMetrics getWindowMetrics(Activity activity) { DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); return metrics; } }