Code example for GridView

Methods: setColumnWidthsetHorizontalSpacingsetNumColumnssetStretchModesetVerticalSpacing, setDrawSelectorOnTop, setId, setOverScrollMode, setSmoothScrollbarEnabled

0
        tv.setId(INTERNAL_EMPTY_ID);
        tv.setGravity(Gravity.CENTER);
        lframe.addView(tv, new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
 
        GridView lv = new GridView(getActivity());
        lv.setId(android.R.id.list);
        lv.setDrawSelectorOnTop(false);
        lv.setColumnWidth(convertDpToPixels(60, getActivity()));
        lv.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
        lv.setNumColumns(GridView.AUTO_FIT);
        lv.setHorizontalSpacing(convertDpToPixels(20, getActivity()));
        lv.setVerticalSpacing(convertDpToPixels(20, getActivity()));
        lv.setSmoothScrollbarEnabled(true);
 
        // disable overscroll 
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
            lv.setOverScrollMode(ListView.OVER_SCROLL_NEVER);
        } 
 
        lframe.addView(lv, new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));