不同设备的网格数 [英] Number of grids for different devices

查看:22
本文介绍了不同设备的网格数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我应该知道为不同设备显示的每一行中 gridview 的数量.比如平板电脑、WVGA 手机每行的 gridview 数量..因为它们的屏幕宽度不同..有没有代码可以检查这个?

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?

推荐答案

好的,您可以使用

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

其中 100 是所有设备每列的固定宽度……我在平板电脑中得到 8 列,在三星 2.2 设备中得到 3 列,在三星笔记中得到 4 列

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

这篇关于不同设备的网格数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆