开发者

Drawable folders in res folder?

What is the difference between the three drawable folders in the res folder in the project hierarchy? If I have an image to put into 开发者_JAVA百科a folder, which folder do I put it in?


I am going to take a guess that "the three drawable folders" are drawable-ldpi, drawable-mdpi, and drawable-hdpi. In that case, if you stick with all of those folders, you need to put one image in each, sized to match the indicated screen density. This is discussed in the online documentation as well as this blog post. You can find a set of sample projects showing use of different drawable resources based on screen density here.

If you are just starting out in Android development, you can get rid of all three of those directories and create a single drawable directory, putting your image in there. Eventually, though, for a quality application, you will want to test your images on different devices/emulators with different screen densities, and possibly have different images for each density to improve the look of your app.


Here is a reference to multi device options.

As said by @CommonsWare, you don't need to put resources in anything but res/ layout/ or drawable/ but if you want your program to have a better experience on multiple devices with different screens / density / languages you may want to consider that you have that option.


Also interesting, though not specific to images, is how android handles resources. It gives them a load order, where more specific means it'll get picked over less specific.

For example, you have three String values in strings.xml in your values folder. You also have one specific string in a folder called values-en. When android opens your app and your locale matches en, it will load two defaults from the values folder and the third, more specific string, from values-en. If your locale is ru, it will just use the default instead because you have no values-ru folder.

The same is true for images. If android can't find images for your specific screen variant, it will use defaults from the drawable folder.

In my opinion it's good practice to have default values/images in your generic folders like values/drawable and specific values/images in specific folders. This way both current and future devices will at least have a way to display your content until you can provide specific versions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜