调整XXHDPI的图像大小

时间:2016-02-10 01:03:20

标签: android hdpi

我有一个正好为MDPI显示的图像。 其分辨率为191 x 255.

然后我将它调整为XXDPI,使用1:3比例,它到达573 x 765。 但是,当模拟器显示它时,质量不如MDPI那么好。 它显然很差。

对于这两种情况,我使用它Wrap Content

如果我在图像编辑器上显示两个图像,它们都具有完美的质量。 为什么会这样?我在这里错过了什么吗?

2 个答案:

答案 0 :(得分:1)

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
}

答案 1 :(得分:0)

你可以添加android:scaleType =&#34; 。 。 。 &#34;你要什么样的图像显示

相关问题