Java tutorial
//package com.java2s; //License from project: Apache License import android.app.Activity; public class Main { public static int getImageItemWidth(Activity activity) { int screenWidth = activity.getResources().getDisplayMetrics().widthPixels; int densityDpi = activity.getResources().getDisplayMetrics().densityDpi; int cols = screenWidth / densityDpi; cols = cols < 3 ? 3 : cols; int columnSpace = (int) (2 * activity.getResources().getDisplayMetrics().density); return (screenWidth - columnSpace * (cols - 1)) / cols; } }