问题描述
我已经把在一个图像的ImageButton
,这看起来很不错的一个MDPI(中DPI )屏幕。然而,当该设备具有华电国际(高DPI )屏幕,图像仍然逐像素精确的,这一下小的设备屏幕上。
I have an image put on an ImageButton
, which looks good on a mdpi (medium-dpi) screen. However, when the device has a hdpi (high-dpi) screen, the image is still pixel-by-pixel accurate, which look small on the device screen.
我如何作出这样的图像(因此的ImageButton
)比例基础上,密度无关像素( DP 或浸)而不是像素?
How do I make such that the image (and therefore the ImageButton
) scaled based on the density-independent pixels (dp or dip) instead of pixels?
推荐答案
由于ponkin提到,9补丁是你最好的选择。结合资源目录预选赛(绘制 - 华电国际
,绘制-MDPI
等),你可以使好看资产在任何密度和大小。
As ponkin mentioned, 9-patches are your best bet. Combined with resource directory qualifiers (drawable-hdpi
, drawable-mdpi
, etc.) you can make assets that look good at any density and size.
9,补丁和资源目录限定词的例子可以在多分辨率可以找到 Android SDK中的样品。半透明,黑色,圆角背景被实现为9贴片具有不同的PNG为LDPI,MDPI,和HDPI
An example of 9-patches and resource directory qualifiers can be found in the Multiple Resolutions Android SDK sample. The semi-transparent, black, rounded-corner background is implemented as a 9-patch with different PNGs for ldpi, mdpi, and hdpi.
这篇关于如何使ImageButton的Android中尺度自动根据屏幕像素密度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!