Tag: gridlayout Manager

August 13, 2021

Android: Dynamic column number in GridView and Gridlayout manager

If you want to change grid item dynamically then follow these steps. This will help you to achieve your goal. For GridView just do : final GridView gridView = (GridView) rootView.findViewById(R.id.gridView); int gridViewEntrySize = getResources().getDimensionPixelSize(R.dimen.grip_view_entry_size); int gridViewSpacing = getResources().getDimensionPixelSize(R.dimen.grip_view_spacing); WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int numColumns = (display.getWidth() – gridViewSpacing) / (gridViewEntrySize + gridViewSpacing); gridView.setNumColumns(numColumns); For Recyclerview use this layout manager […]