Code example for GridView

Methods: getNumColumns

0
    private int getImageHeight(final GridView gridView) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
            return (int)(gridView.getColumnWidth() * IMAGE_SIZE_RATIO);
 
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
            return (int)((getScreenWidth() / gridView.getNumColumns()) * IMAGE_SIZE_RATIO);
 
        return imgHeight;
    } 
 
    public int getScreenWidth() { 
        if (context == null)
            return 0; 
 
        return getDisplayMetrics().widthPixels;
    } 
 
    public DisplayMetrics getDisplayMetrics() {
        final WindowManager windowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
        final DisplayMetrics metrics = new DisplayMetrics();
        windowManager.getDefaultDisplay().getMetrics(metrics);