在GridView的调整在Android上的图像 [英] Resize images in GridView on Android

查看:143
本文介绍了在GridView的调整在Android上的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照这个教程来创建一个 的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;
}

这篇关于在GridView的调整在Android上的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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