【问题标题】:Icon image in circle shape is blurry圆形图标图像模糊
【发布时间】:2016-03-03 13:15:54
【问题描述】:

我创建了包含 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>

片段.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" />

【问题讨论】:

    标签: android android-layout android-imageview android-drawable android-shape


    【解决方案1】:

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

    【讨论】:

    • 我正在测试的平板电脑是三星 Galaxy TM-330,其密度约为 189。这介于中等和高之间。我认为下载包含每个密度相同图标的 zip 文件夹的全部意义在于考虑每个屏幕密度。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-30
      • 1970-01-01
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多