get GridView Vertical Spacing - Android User Interface

Android examples for User Interface:GridView

Description

get GridView Vertical Spacing

Demo Code


//package com.java2s;

import android.widget.GridView;

import java.lang.reflect.Field;

public class Main {

    public static int getGridViewVerticalSpacing(GridView view) {
        // get mVerticalSpacing by android.widget.GridView
        Class<?> demo = null;
        int verticalSpacing = 0;
        try {/* w  w  w.j  a  v a  2  s  .  c o m*/
            demo = Class.forName("android.widget.GridView");
            Field field = demo.getDeclaredField("mVerticalSpacing");
            field.setAccessible(true);
            verticalSpacing = (Integer) field.get(view);
            return verticalSpacing;
        } catch (Exception e) {
            /**
             * accept all exception, include ClassNotFoundException, NoSuchFieldException, InstantiationException,
             * IllegalArgumentException, IllegalAccessException, NullPointException
             */
            e.printStackTrace();
        }
        return verticalSpacing;
    }
}

Related Tutorials