我创建了包含png图标的圆形图形。根据Android材料准则,圆的直径为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" />
我正在测试的平板电脑是三星Galaxy TM-330,其密度约为189。这介于中等和高。我认为下载包含每个密度相同图标的zip文件夹的重点是考虑每个屏幕密度。 –