我有一张可以完美显示 MDPI 的图像。其分辨率为191 x 255.
然后我将其调整为 XXDPI,使用 1:3 的比例,它变为573 x 765
. 尽管如此,当模拟器显示它时,质量还是不如 MDPI 的。它显然很穷。
对于这两种情况,我都在使用它Wrap Content
如果我在图像编辑器上显示这两个图像,它们具有完美的质量。为什么会这样?我在这里错过了什么吗?
DisplayMetrics metrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
int widthPixels = metrics.widthPixels;
int heightPixels = metrics.heightPixels;
float widthDpi = metrics.xdpi;
float heightDpi = metrics.ydpi;
float widthInches = widthPixels / widthDpi;
float heightInches = heightPixels / heightDpi;
double diagonalInches = Math.sqrt((widthInches * widthInches) + (heightInches * heightInches)); // this code returns the actual screen size (eg. 7,8,9,10 inches in double format ex: 7.932189832)
diagonalInches = (double) Math.round(diagonalInches * 10) / 10; // round up to first decimal places
ArrayList<Integer> imageId = new ArrayList<>();
imageId.clear();
for (Integer i : imageNum){ // uses loop since im using TransitionDrawable to change images in single view
String stringID;
if (isPortrait) {
stringID = "featured_img_" + i.toString() + "_port"; // portrait images
} else {
if (diagonalInches >= 7 && diagonalInches <=8){
stringID = "featured_img_" + i.toString() + "_land_b"; // landscape images this is the drawable filename
} else {
stringID = "featured_img_" + i.toString() + "_land_a"; //landscape images this is the drawable filename
}
}
int drawableId = getResId(stringID);
imageId.add(drawableId); // adding it to arraylist
}
您可以添加 android:scaleType=" . . . " 在您想要显示图像的内容上