Android-根据设备分辨率调整多媒体资料中的图像大小

Android-根据设备分辨率调整多媒体资料中的图像大小,android,image,gallery,resolution,Android,Image,Gallery,Resolution,我有一个Android应用程序,可以从网络上获取图像。 然而,当我设定: <supports-screens android:anyDensity="true" /> 有没有办法检测使用的分辨率,然后调整多媒体资料中图像的大小,使其延伸到屏幕的宽度?试试看 i.setAdjustViewBounds(true); 另外,您不应该使用硬编码像素值(在i.setLayoutParams(new Gallery.LayoutParams(400300));) 使用 在一些xml文件中(

我有一个Android应用程序,可以从网络上获取图像。 然而,当我设定:

<supports-screens android:anyDensity="true" />
有没有办法检测使用的分辨率,然后调整多媒体资料中图像的大小,使其延伸到屏幕的宽度?

试试看

i.setAdjustViewBounds(true);
另外,您不应该使用硬编码像素值(在
i.setLayoutParams(new Gallery.LayoutParams(400300));

使用

在一些xml文件中(在res/values下)


400dp
300dp
ImageView i = new ImageView(mContext);
i.setImageDrawable(drawablesFromUrl[position]);
i.setLayoutParams(new Gallery.LayoutParams(400, 300));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);
i.setAdjustViewBounds(true);
int width = (int) getResources().getDimension(R.dimen.image_width)
int height = (int) getResources().getDimension(R.dimen.image_height)
i.setLayoutParams(new Gallery.LayoutParams(width, height));
<?xml version="1.0" encoding="utf-8"?>
<resources>
  <dimen name="image_height">400dp</dimen>
  <dimen name="image_width">300dp</dimen>
</resources>