3

For my app, I need to have same images with 2 or 3 different sizes

Or I wonder if it would be possible to take the drawables from another drawable-folder (ie: the same images with different resolutions are available like that)

Else, I should copy the same image several times in each drawable folder (mdpi, hdpi, xhdpi)

Ex: I have drawable ima in hdpi folder and I need the same images smaller and greater which are available in mdpi and xhdpi folder => How can i get them or do I have to copy the images I need in the hdpi folder ?

Excuse me for my bad english

Thanks for helping me

sagat06
  • 31
  • 2

3 Answers3

0

folders named mdpi, hdpi, xhdpi is for random devices , I mean there are for devices with random screens. There are 4 type of android devices considering from screen. small, normal , large , extralarge and that's why there are these folders , why you don't want to change your pictures names? If it's didn't help can you explain your question more recognizable? I don't sure I andertood question normally :)

Regards Hayk Nahapetyan

Hayk Nahapetyan
  • 4,452
  • 8
  • 42
  • 61
0

try like this programmatically..

InputStream is=this.getResources().getAssets().open("drawable.png");

is=this.getResources().openRawResource(R.raw.myDrawable); 

or

If you want to use the path try the following :

private void showImage() {
    String uri = "drawable/icon";

    // int imageResource = R.drawable.icon;
    int imageResource = getResources().getIdentifier(uri, null, getPackageName());

    ImageView imageView = (ImageView) findViewById(R.id.myImageView);
    Drawable image = getResources().getDrawable(imageResource);
    imageView.setImageDrawable(image);
}

But it's recommended to use the R references :

int imageResource = R.drawable.icon; 

Drawable image = getResources().getDrawable(imageResource);

Source

drawable-hdpi drawable-mdpi,drawable-ldpi are just different folders to make difference between images quality depending on the screen resolution. The idea is to put the same images in different folder with different resolutions ...

Community
  • 1
  • 1
Rahul Baradia
  • 11,802
  • 17
  • 73
  • 121
  • In fact, I understand what the drawable folders are. i just wanted to know if it's posible to act kinda like that => int imageResource = R.drawable-hdpi.icon; – sagat06 Dec 13 '12 at 14:19
  • put your image in drawable.hdpi which you want to use – Rahul Baradia Dec 13 '12 at 14:26
  • For example, i want to access to the drawable.hdpi with a mdpi device... That's the problem. Actually, i had an image ima1 in each drawable folder and i have to copy and rename ima1 from drawable.hdpi to drawable.mdpi for using it with a mdpi device – sagat06 Dec 13 '12 at 14:36
0

I'm not sure that I completely understand you but as for me you should logically organize your drawables and put them to assets folder not to resources. Then you can use them as you want.

Also I think there are no way to access resources from another screen.

Hope I understand you post right.

EDIT
API Level 15 introduced Resources.getDrawableForDensity() method. As far as I understood there is no way to launch it on older versions.

Viacheslav
  • 5,443
  • 1
  • 29
  • 36
  • I think you understood what I wanted to know. So, It's impossible to access ressources from another screen (= another drawable folder) ? I wanted to do that for limiting the drawables in my app, but i think I keep doing like i actually do, the images i need in each drawable folders, it will be more simple. Thanks – sagat06 Dec 13 '12 at 14:16
  • I'm sure for 99.99% that it's impossible but I don't try this. The reason I'm sure is you have access to resources only via R.java and Android resolve resources for you depending on resource modifier (screen size, locale or else). I don't know what your app is but if you have a lot of images you can significantly increase APK size if you will use multiple sets of images in one drawable-xxx folder. – Viacheslav Dec 13 '12 at 14:32
  • I understand what you mean, i will take informations about the assets folder. But I already see the consequence, I'll have to use different layout folder for using the right images (they won't have the same name compared with the drawable folder) – sagat06 Dec 13 '12 at 15:06