简体   繁体   English

Android:如何创建不同大小和密度的图像?

[英]Android : How to create images for different sizes and densities?

I have an image view which has different size on normal and large sized screens(I achived it via dimens.xml), lets assume 100*100 dp on small and 133*133 dp on large sized screen. 我有一个图像视图,在普通和大型屏幕上都有不同的尺寸(我是通过dimens.xml实现的),假设在小型屏幕上为100 * 100 dp,在大型屏幕上为133 * 133 dp。

I'm setting image to it programatically, let's say it is def.png 我以编程方式为其设置图片,假设它是def.png

Now for best performance I should create 6 versions of def.png(assuming i cater only to mdpi, hdpi and xhdpi densities) 现在为了获得最佳性能,我应该创建def.png的6个版本(假设我仅满足mdpi,hdpi和xhdpi密度)

  1. small-mdpi - 100*100 px 小mdpi-100 * 100 px
  2. small-hdpi - 150*150 px 小hdpi-150 * 150 px
  3. small-xhdpi - 200*200 px 小xhdpi-200 * 200像素

  4. large-mdpi - 133*133 px 大mdpi-133 * 133 px

  5. large-hdpi - 199*199 px 大hdpi-199 * 199 px
  6. large-xhdpi - 266*266 px 大xhdpi-266 * 266 px

It means 6 def.png images, but I can put 3 of them because only 3 folders are available ie drawable-mdpi, drawable-hdpi, drawable-xhdpi . 这意味着6张def.png图像,但是我可以放3张,因为只有3个文件夹可用,即drawable-mdpi,drawable-hdpi和drawable-xhdpi

How should I achieve best performance so that there will be less scaling up and down of Images ?? 我应该如何获得最佳性能,以减少图像的放大和缩小?

or 要么

If it is not possible this way, then what are the alternatives ? 如果无法通过这种方式,那么有哪些替代方案?

How to Support Multiple Screens:- 如何支持多个屏幕:

  • Explicitly declare in the manifest which screen sizes your application supports 在清单中明确声明您的应用程序支持哪种屏幕尺寸
  • Provide different layouts for different screen sizes 为不同的屏幕尺寸提供不同的布局
  • Provide different bitmap drawables for different screen densities 为不同的屏幕密度提供不同的位图可绘制对象

Source :- https://developer.android.com/guide/practices/screens_support.html#support 来源: -https : //developer.android.com/guide/practices/screens_support.html#support

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM