图像视图质量

ImageView quality

我刚刚完成我的应用程序,所以我在平板电脑上测试了它,质量很好,但是当我在我的智能手机 (HTC One) 上试用它时,我的质量很差,所以我想知道为什么。

layour-normal:

<ImageView
    android:layout_width="210dp"
    android:layout_height="90dp"
    android:id="@+id/topLogo"
    android:layout_marginTop="5dp"
    android:src="@drawable/logo_bleu_petit"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

image-size: 250*107



您的项目的 res 文件夹中有不同的 drawable 文件夹。您必须在不同的可绘制文件夹中提供具有相同名称但大小不同的相同图像文件,这样当您 运行 您的应用程序在任何设备上时,它都会根据其分辨率自动拍摄图像。

立即尝试...获取屏幕分辨率,然后将图像用于 imageview...

int screenSize = getResources().getConfiguration().screenLayout &
        Configuration.SCREENLAYOUT_SIZE_MASK;

String toastMsg;
switch(screenSize) {
    case Configuration.SCREENLAYOUT_SIZE_LARGE:
        toastMsg = "Large screen";
        break;
    case Configuration.SCREENLAYOUT_SIZE_NORMAL:
        toastMsg = "Normal screen";
        break;
    case Configuration.SCREENLAYOUT_SIZE_SMALL:
        toastMsg = "Small screen";
        break;
    default:
        toastMsg = "Screen size is neither large, normal or small";
}
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();

不同的图片应该放在不同的drawable文件夹中。 例如,将 250*107 的图像放在 /res/drawable-mdpi 中,将相同图像的 500*214 版本放在 /res/drawable-hdpi 中。 该应用程序将在具有不同屏幕尺寸的设备上显示不同的图像。 如果在 /res/drawable 中只有一张低质量图像,当您使用具有 1080p 屏幕的设备时,图像可能会放大 2 倍或 4x.Then 看起来质量很差。

还有一件事,尽量不要在 ImageView.Use scaleType 上使用固定的宽度或高度,这样 ImageView 可以更好地处理不同大小的图像。