如何确定资源文件中使用? [英] How to identify resource file in use?

查看:114
本文介绍了如何确定资源文件中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

拥有一批图像文件资源,例如image01.png,image02.png ....

Have a number of image files resources e.g. image01.png, image02.png....

我已经设置了不同的区域设置/分辨率/取向资源文件夹预选赛例如

I have have set up resource folders with different locale/resolution/orientation qualifiers e.g.

/res/drawable-en-mdpi-port
/res/drawable-en-mdpi-land
/res/drawable-fr-hdpi-port...........

在每个图像文件不同(宽高比/分辨率/区域设置specfic图片)

Image files in each differ (aspect ratio/resolution/locale-specfic image)

反正是有确定哪个实际的资源文件是在应用程序中使用?
将是我有用的测试将它发送出去的调试日志,这样可以确保正确的图像文件正在使用,即我已经设置了资源预选赛正确并放在正确的图像正确的文件夹。

Is there anyway to programatically determine which actual resource file is in use in application? Would be useful to me for testing to send it out on debug log, so can be sure correct image file is being used i.e. I have set-up resource qualifiers correctly and placed correct images in correct folders.

可以手动执行此操作,但由于图片数量的增加这将成为一个重要的苦差事。

Can do this manually, but as number of images increases this becomes a major chore.

我是从如何确定,这是不可能的资源路径类似的问题的猜测。
如果没有,没有任何人有什么招数/提示吗?我可以添加一个ID文本图像(甚至使用脚本文件名为批量水印图像),但会很高兴地听到,如果有一个简单的方法。

I am guessing from similar questions about determining resource paths that this may not be possible. If not, does anyone have any tricks/tips? I could add an ID text to image (maybe even use a script to batch watermark images with filename) but would be happy to hear if there is a simpler way.

推荐答案

如果你想知道什么PNG文件,是当前(当前配置),说 R.drawable.icon ,你可以这样做:

If you wonder what PNG file that is currently (with the current configuration) loaded for, say R.drawable.icon, you can do this:

TypedValue returnedValue = new TypedValue();
getResources().openRawResource(R.drawable.icon, returnedValue);
Log.d("Example", "Path to loaded resource: " + returnedValue.string);

在hdpi设备上,输出将是:

on an hdpi device, the output will be:

D/Example ( 2028): Path to loaded resource: res/drawable-hdpi/icon.png

这会给你的路径,路径多么复杂独立使用的实际资源。它仅适用于属于您的apk文件中的单个文件,即使资源,最主要的是可绘。

This will give you the path to the actual resources used independently of how complex the path is. It only works for resources that are individual files within your .apk though, most notably drawables.

这篇关于如何确定资源文件中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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