问题
I don't understand the benefit of resources configuration qualifiers designed to support multiple screen densities, for example :
for an mdpi you put an icon of 100x100 px
for an hdpi you put an icon of 150x150 px
for an xhdpi you put an icon of 200x200 px
Then you display this icon in an imageView of dimensions 100 x 100 dip which already maintains its size on multiple screens of different sizes and densities.
Why don't we just use the xhdpi version of the icon in the resources above as a baseline resource so that it gets displayed nice and smooth on higher density screens, and at the same time android will rescale it to fit lower density screens for which the xhdpi version of the icon will be enough anyway?
I hope I am clear in my explanation, thanks
回答1:
You are certainly welcome to just ship -xhdpi
drawables and have Android downsample as needed. I expect that many developers do just that.
However, please understand that you are no longer in control over what your drawables look like on lower densities. You are placing your trust in Android's drawable resampling algorithm, which:
is going to be more optimized for low CPU and memory use than would a desktop OS graphics tool, and therefore may not be as good of quality; and
may vary by Android OS version
Shipping alternative artwork in different densities gives you more control, albeit for greater development effort and a larger APK size.
If you do not want that control, that is your choice. At the same time, please do not begrudge other developers' desire to have that control and have potentially higher quality results on lower-density devices.
回答2:
The main reason for that is basically letting you define multiple layouts for each screen size with the possibility to change the "SAME" graphics from a screen size to another, let me give you an example: Imagine that you have an activity which its layout is defined for mdpi and hdpi screens. In the hdpi screen you show a full banner with text inside (let's assume the resource is for this banner is R.drawable.topbanner), however this banner is not comfortable to show in smaller screen like mdpi after resizing, so you decided to make a timmed version of this banner for the mdpi screens with the same resource id (R.drawable.topbanner) in which you removed some text for example. Now the system will decide, depending on the screen size, which one to use.
来源:https://stackoverflow.com/questions/27892717/ui-for-different-screen-densities