How do I change column count of a GridLayout dynamically in Android Studio? -


i want set number of column of gridlayout width of window.

but, these sort of codes don't work in oncreate() function.

gridlayout glayout = (gridlayout)findviewbyid(r.id.a_grid_layout); glayout.setcolumncount(4); 

if want set numbers of columns based on width of gridlayout, must override onmeasure method. provides widthspec , heightspec parameters, can actual width , height in pixels using measurespec.getsize(). there, calculate how many columns you'd show based on width of gridlayout found, , use setcolumncount make display number of columns.


Comments

Popular posts from this blog

gcc - MinGW's ld cannot perform PE operations on non PE output file -

How to connect android app to App engine -

hadoop - Running Map Reduce Job shows error - Mkdirs failed to create /var/folders/ -