Number of grids for different devices

前端 未结 2 1803
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-03 10:37

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

相关标签:
2条回答
  • 2021-01-03 11:19

    Try this method, getNumColumns();

    This will provide you with the column count.

    Usage:

    gridView.getNumColumns();
    
    0 讨论(0)
  • 2021-01-03 11:23

    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

    0 讨论(0)
提交回复
热议问题