在我的应用程序中,我有带图标的按钮。这些图标在 drawable-ldpi-v4/、drawable/和 drawable-hdpi-v4/中以三种密度提供为 PNG 图像。这是一个示例:
每个图标都显示在一个 ImageButton 中:
<ImageButton style="@style/Shortcut" android:id="@+id/open_button"
android:src="@drawable/shortcut_open" android:layout_marginRight="4dp"/>
哪里Shortcut
风格是:
<style name="Shortcut">
<item name="android:layout_width">65dp</item>
<item name="android:layout_height">45dp</item>
<item name="android:scaleType">center</item>
<item name="android:background">@drawable/shortcut_background</item>
</style>
但是,在某些设备/平台版本上,某些图标会被更改、模糊等等。我不确定它是否在缩放,我认为它更像是一个渲染错误。我曾尝试禁用 BitmapDrawable 上的抗锯齿功能,但这没有帮助。
如下图所示,在 Android 2.1 LDPI 上,一个图标被损坏/裁剪,在 Android 1.6 MDPI 和 Android 2.1 HDPI 上,图标底部似乎随机添加了一条额外的线(仔细观察) .
在 list 中,我有一个空的 <supports-screens />
按照有关 supporting multiple screens in legacy apps 的文档中的建议.添加anyDensity="true"
没有帮助。
显然,从 Froyo 开始,情况变得更好,如您在上图中所见。但是我如何在 Android <= 2.1 上解决这个问题?
最佳答案
我认为您不应该为按钮使用明确的尺寸(即使表示为倾斜),而应该让系统为您完成。
使用
<ImageButton android:id="@+id/SpeakButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
也可能是您落入了其他人报告的“dip”与“dp”陷阱,其中文档说它们是同义词,但使用“dip”使事情按预期工作。
关于android - 如何在不改变 ImageButton/ImageView 的情况下显示图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5516066/