在GridView的调整在Android上的图像图像、GridView、Android

2023-09-05 00:14:20 作者:萌、小兮℡

我按照这个教程来创建一个 的GridView

I follow this tutorial to create a GridView:

这行:

imageView.setLayoutParams(new GridView.LayoutParams(85, 85));

尺寸85x85是伟大的,我的野火,但在HTC Desire的它看起来非常小。 根据屏幕我怎样才能改变图像大小?

Size 85x85 is great for my Wildfire, but on HTC Desire it looks very small. How can I change the image size according to the screen?

我有2个不同的布局,但的GridView 还没有在XML文件中的任何属性来改变图片大小。

I have 2 different layouts, but Gridview hasn't any attribute in the XML files to change the image size.

推荐答案

您可以尝试进行调整基于关闭当前设备,你是对的像素密度。

You could try to make an adjustment based off the pixel density of the current device you are on.

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
switch(metrics.densityDpi){
     case DisplayMetrics.DENSITY_LOW:
                imageView.setLayoutParams(new GridView.LayoutParams(lowVal, lowVal));
                break;
     case DisplayMetrics.DENSITY_MEDIUM:
                imageView.setLayoutParams(new GridView.LayoutParams(medVal, medVal));
                break;
     case DisplayMetrics.DENSITY_HIGH:
                 imageView.setLayoutParams(new GridView.LayoutParams(highVal, highVal));
                 break;
}