0
我正在制作一个Android应用程序。这将使用将覆盖屏幕宽度的图像。宽高比应该是16:9。图像将通过互联网加载。存储在服务器上的映像的大小应该是多少,以便适用于最大设备的最小设备。我不想保持非常大的尺寸,因为这可能会降低性能。适当的图像大小
我正在制作一个Android应用程序。这将使用将覆盖屏幕宽度的图像。宽高比应该是16:9。图像将通过互联网加载。存储在服务器上的映像的大小应该是多少,以便适用于最大设备的最小设备。我不想保持非常大的尺寸,因为这可能会降低性能。适当的图像大小
您可以根据此屏幕保持图像,并可以在所有的屏幕尺寸工作。
Normal xhdpi - 640×960 (1280×1920 in design)
您可以在下面的链接中找到解决方案。 enter link description here
在这里你可以找到方法
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height/2;
final int halfWidth = width/2;
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight/inSampleSize) > reqHeight
&& (halfWidth/inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;}
您可以直接使用这样
mImageView.setImageBitmap(
decodeSampledBitmapFromResource(getResources(), R.id.myimage, 100, 100));