如何访问RES /绘制/"文件夹" [英] How to access res/drawable/"folder"

查看:125
本文介绍了如何访问RES /绘制/"文件夹"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序有很多,我都分为文件夹下RES /绘制的图片。但是Android忽略了最低,让我进入他们药谷R。有没有一种方法来访问这些文件夹。

On my application I have many pictures which I have grouped in folder under res/drawable. But Android dosen't let me access them trough "R". Is there a way to access those folders.

这是使用为code IM。

This is the Code im using for.

    ImageView iv = new ImageView(conext);
    iv.setImageResource(R.drawable.**smiley.666**);

标志着我,我不能访问的部分。

I marked the part which I can't access.

THX提前

野生动物园

推荐答案

没有,安卓不允许在 / RES /绘制子文件夹:<一href="http://stackoverflow.com/questions/1077357/can-the-android-drawable-directory-contain-subdirectories">Can Android的绘制目录包含子目录?

No, Android does not allow subfolders under /res/drawable: Can The Android drawable directory contain subdirectories?

您可以但是,添加所有图像文件在 /绘制,然后通过访问这些编程方式:

You can however, add all image files under /drawable and then access them programmatically via:

int drawableID = context.getResources().getIdentifier("drawableName", "drawable", getPackageName());
iv.setImageResource(drawableID);

其中, drawableName 是绘制文件的名称,即 MYIMAGE 如果图像文件 myimage.jpg

Where drawableName is a name of the drawable file, i.e. myimage if image file is myimage.jpg.

在code以上将获得id为图像资源 R.drawable.drawableName

The code above will get image resource with id R.drawable.drawableName.

这篇关于如何访问RES /绘制/&QUOT;文件夹&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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