我正在Emulator Pixel 4,API 33中测试这一点.

我在drawable文件夹中添加了一些drawablexdrawable的PNG图像,但它们都是模糊的.我把每一个都复制并粘贴到文件夹里.我试过android:src="drawable/..."android:background="drawable/..."android:scaleType="fitXY"android:adjustViewBounds="true"和每一种的不同组合,但图像总是模糊.我甚至试过CircleImageView、Glide和毕加索,但模糊效果仍然存在.我的所有图像都会发生这种情况,但BottomNavigationView中的图像除外

以下是其中之一的一个例子:

enter image description here

这里是底部的导航视图,但不是那么模糊.我猜是因为它缩小了.

enter image description here

在iOS中,他们使用1x、2x、3x映像.我把上面的https://hotpot.ai/blog/ios-1x-2x-3x-generatorxhttps://hotpot.ai/blog/ios-1x-2x-3x-generator图像放到一个类似https://hotpot.ai/blog/ios-1x-2x-3x-generator的程序中,然后一旦我把图像拖到Assets文件夹中,我就不必担心模糊了(我有3个版本).在iOS中,同样的https://hotpot.ai/blog/ios-1x-2x-3x-generatorxhttps://hotpot.ai/blog/ios-1x-2x-3x-generator图像显示为sharp

问题是我复制并粘贴图像到Drawables文件夹,但我需要1x, 1.5x, 2x, 3x, and 4x个版本的图像吗?顺便说一句,我还在学习Android.

示例代码:

<androidx.constraintlayout.widget.ConstraintLayout

    <ImageView
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:src="drawable/profile_icon"
            android:scaleType="fitXY"
            android:adjustViewBounds="true"
            .../>
        <TextView

    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="drawable/profile_icon"
            android:scaleType="fitXY" // I've tried multiple scaleTypes 
            android:adjustViewBounds="true"
            .../>
        <TextView 

推荐答案

问题是我是否将图像复制并粘贴到Drawables文件夹中,但我需要图像的1x、1.5x、2x、3x和4x版本?

是.向量可绘制文件和其他XML定义的可绘制文件最多使用res/drawable/.对于位图,请使用:

  • res/drawable-mdpi/(1x)
  • res/drawable-hdpi/(1.5x)
  • res/drawable-xhdpi/(2x)
  • res/drawable-xxhdpi/(3x)
  • res/drawable-xxxhdpi/(4x)

这一点在the documentation中有更多的介绍.

Android相关问答推荐

广播接收者意图从服务内设置,而不被其他服务接收

将Any强制转换为Integer将从API返回NullPointerException

Jetpack Compose中的导航找不到NavHost类的名称为:startDestination";的参数

如何从URI中获取图像大小

返回并再次打开webview时webview无法打开相机

升级到 Jetpack Compose 物料 list 2023.08.00 需要我将 targetSdk 更改为 34

retrofit2.HttpException: HTTP 401

在 Android 房间迁移中获取上下文

如何仅使用您的 Android 应用程序定位平板电脑?

系统导航栏在某些场景下应用了深色效果

从 Jetpack Compose 中的 IconButton 中删除黑色色调

从活动共享视图模型以使用 hilt 组合函数

Jetpack Compose 中的滑动按钮菜单

观察软键盘可见性,打开/关闭 Jetpack Compose

Jetpack compose 为网络检索视频帧导致延迟

从 Firebase 云存储中获取照片会导致 Android Jetpack Compose 闪烁

如何在 react native 应用程序中显示复选框?当它在 android 模拟器中可见时

如何对齐文本和图标可组合,以便即使在文本溢出后它们也能保持在一起?

禁用通知权限后启动前台服务导致崩溃(Android 13)

如果我在网络请求中指定它们是否与判断网络功能相关