圆形图标图像模糊

Icon image in circle shape is blurry

我创建了包含 png 图标的圆形可绘制对象。根据 Android Material 准则,圆的直径为 40dp,图标为 24dp。最初我没有为左、右、上和下设置任何值,因为我假设内部图标项将保持 24dp。但是,它会调整大小。然后我尝试使用宽度和高度属性将其强制为 24dp,这在 AS 的预览中似乎有效,但对平板电脑没有影响。最后,我设置了顶部、底部、左侧和右侧的值,如图所示。我将 8dp 用作:(40-24)/2 = 8。

问题是圆圈内的图标看起来很模糊,好像它被调整了大小,但我不知道如何处理这个问题。也许有更好的方法将图标放在圆圈内。毕竟,这是一种非常常见的设计实践。

我已将实际图标放在所附图片中的圆圈旁边进行比较,但不幸的是,由于图片压缩,很难分辨清晰度的差异,但请相信我的话,右边的图片看起来像一个向量,就像 FAB 中的向量一样。

circle_grid.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval">

            <solid
                android:color="@color/colorPrimary"/>

            <size
                android:width="40dp"
                android:height="40dp"/>
        </shape>
    </item>
    <item android:drawable="@drawable/ic_grid_on_white_24dp"
        android:top="8dp"
        android:bottom="8dp"
        android:left="8dp"
        android:right="8dp"
        android:gravity="center"/>
</layer-list>

fragment.xml

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="@dimen/screen_edge_margin"
            android:layout_marginStart="@dimen/screen_edge_margin"
            android:src="@drawable/circle_grid" />

您正在使用的设备的 DP 组是什么?如果您的设备是 hdpi DP,则图标的像素大小应为 36*36。如果它在 xhdpi 组中,它应该有 48*48 像素大小。如果它在 xxhdpi 组中,那么它的大小应该为 72*72。等等等等。我相信该图标只有一种尺寸,这就是为什么它看起来很模糊的原因

http://www.sweet-web-design.com/wordpress/android-tricks-drawable-objects-or-how-to-draw-a-circle/2874/

这在没有导致图像重新缩放和像素化的情况下有效。