Number of grids for different devices

穿精又带淫゛_ 提交于 2019-12-18 17:55:23

问题


I have a problem where i should know the number of gridviewin each row which gets displayed for different devices. like number of gridview per row for tablets, WVGA phones ..since their screen widths are different ..is there a code to check this?


回答1:


Okk you can set number of columns programatically using

float scalefactor = getResources().getDisplayMetrics().density * 100;
int width = getWindowManager().getDefaultDisplay().getWidth();
int columns = (int) ((float)width / (float) scalefactor);
gridView.setNumColumns(columns);

where 100 is the fixed width of each column for all devices m taking...i get 8 columns in tablet,3 in samsung 2.2 devices and 4 in samsung note




回答2:


Try this method, getNumColumns();

This will provide you with the column count.

Usage:

gridView.getNumColumns();


来源:https://stackoverflow.com/questions/14133693/number-of-grids-for-different-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!