Android的 - 添加图片到项目 [英] Android - Adding Images To Project

查看:425
本文介绍了Android的 - 添加图片到项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是全新的,以安卓,我使用的Eclipse ADT 来创建一个简单的应用程序。此应用程序有一个按钮,根据用户点击改变它的背景图片。

I am brand new to Android and I am using Eclipse ADT to create a simple application. This application has a button that changes it's background image based on user clicks.

我注意到,有4个文件夹在我的项目图片:绘制,华电国际,绘制,LDPI,绘制,MDPI,并绘制-xhdpi

I noticed that there are 4 folders for images in my project: drawable-hdpi, drawable-ldpi, drawable-mdpi, and drawable-xhdpi.

和我也注意到,这是目前存在(启动器图标)的图像都是不同的大小。

and I also noticed that the images that are in there currently (the launcher icon) are all different sizes.

这是否意味着我必须使用一些图像编辑软件来创建一个图像的每个分辨率为每个我的图片吗?或者,(希望)有没有办法来导入图像,并有这个自动为我做的?

Does this mean that I have to use some image editing software to create one image for each resolution for each of my images? Or (hopefully) is there a way to import an image and have this done for me automatically?

谢谢!

推荐答案

图片和其他视觉文件存储在一个或多个可拉伸目录。如果只在一个目录下,Android作为需要将缩放图片。如果一个以上的目录的情况下,机器人将选择适当大小的图像。

Images and other visual files are stored in one or more drawable directories. If only in one directory, Android will scale the image as needed. If more than one directory is used, Android will select the appropriately sized image.

  • 绘制-LDPI - 低密度影像
  • 绘制-MDPI - 中密度图像
  • 绘制 - 华电国际 - 高密度影像
  • 绘制-xhdpi - 超高密度图像(即视网膜般的显示器)
  • 绘制-xxhdpi - 额外额外高密度图像(如Nexus 10的设备,三星Galaxy S4,HTC One和索尼Xperia Z)
  • 绘制-xxxhdpi - 三重超高密度图像(<一href="http://android-developers.blogspot.com/2014/10/getting-your-apps-ready-for-nexus-6-and.html">Nexus 6和9 )
  • drawable-ldpi - Low density images
  • drawable-mdpi - Medium density images
  • drawable-hdpi - High density images
  • drawable-xhdpi - Extra high density images (i.e. retina-like displays)
  • drawable-xxhdpi - Extra extra high density images (devices like Nexus 10, Samsung Galaxy S4, HTC One and Sony Xperia Z)
  • drawable-xxxhdpi - Triple extra high density images (Nexus 6 and 9)

(附注:XML文件也可以被写入并存储作为可绘制这些类型的文件可以控制当多个图像是基于一个视图,或类似的梯度,边框等其他视觉设置的状态下使用)

(Side note: XML files can also be written and stored as drawables. These kinds of files can control when multiple images are to be used based on the state of a view, or other visual settings like gradients, borders, etc.)

那么,是什么的应该的怎么办?

So, what should you do?

为了获得最佳结果(从 Android开发者文档):

要生成这些图片,你应该从你的矢量格式原始资源,并使用以下规模的增加生成每个密度图像:

To generate these images, you should start with your raw resource in vector format and generate the images for each density using the following size scale:

  • xxxhdpi:4.0
  • xxhdpi:3.0
  • xhdpi:2.0
  • 华电国际:1.5
  • tvdpi:1.33(电视只)
  • MDPI:1.0(基线)
  • LDPI:0.75

这意味着,如果你生成一个200x200的图像xhdpi设备,应为华电国际产生同样的资源在150×150,133x133的tvdpi,100×100的MDPI,终于为LDPI设备的一个75x75的形象。

This means that if you generate a 200x200 image for xhdpi devices, you should generate the same resource in 150x150 for hdpi, 133x133 for tvdpi, 100x100 for mdpi, and finally a 75x75 image for ldpi devices.

如果你只是想用一个形象,让Android的规模为您提供:

75%以上,现在有华电国际或更高的分辨率,根据对Android开发者网站上的仪表板。所以,如果你创建一个形象华电国际为例,它的外观完美的有关设备的三分之一,扩大一些,并缩小了约25%的设备。总的来说,我认为你会更好缩减比扩大了。

More than 75% of Android devices now have hdpi or greater resolutions, according to the Dashboard on the Android Developer site. So if you create one image at hdpi, for example, it will look perfect on about a third of devices, scale up for some, and scale down for about 25% of devices. In general I think you'd be better off scaling down than scaling up, too.

这篇关于Android的 - 添加图片到项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆