问题
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