user5803705
user5803705

Reputation:

Android Studio - Drawable folders

I have three general questions regarding android's drawable folders.

  1. Do i put different sized images in each of these folders, or will the images automatically scale themselves? As in, does android decrease the quality of the .bmp files automatically if placed in these folders?
  2. When using the android design preview screen, will the appropriate image from the appropriate drawable folder be shown? If I have to make different sized images for each folder, I want to ensure that what i'm seeing in the design preview matches what is shown on other devices.
  3. Lastly, do the drawable folders, if used, help to avoid the issue with failing to allocate memory for drawables on devices? I have had to scale my images down, and yet my college's phone still cannot allocate enough resources.

I couldn't find answers to these specific questions anywhere, so i'd really appreciate the help with these!

Upvotes: 0

Views: 1152

Answers (4)

lidkxx
lidkxx

Reputation: 2841

Ad 1 I always find it really helpful to load drawables to my project using Android Drawable Importer plugin. It will take care of loading appropriately-sized image into appropriate drawables folder.

Ad 3 If that works for you, maybe try loading images from server using tools like Glade or Picasso? That way you don't clutter your app with unnecessary resources, making it too heavy data-wise. Use a local drawable as placeholder only, in case there's no internet connection.

I'd also recommend using .png over .bmp format, .png are lossless and compressed, meaning your images can get significantly smaller while not losing quality.

Upvotes: 1

Vidhi Dave
Vidhi Dave

Reputation: 5684

  1. You have to put images in different folders as per the image size. it will not generate automatically.

  2. You can not select image for that screen. you can just select different screen sizes android studio will automatically use proper images for that.

  3. For memory issue you can add this line in manifest :

    android:hardwareAccelerated="true"

Upvotes: 0

manuhortet
manuhortet

Reputation: 509

About your first question, you should create four different drawable folders in app>res in order to provide different devices (with different screen sizes and densities) more convenient images.

/drawable-ldpi For low density screens.

/drawable-mdpi For medium density screens.

/drawable-hdpi For high resolution screens.

/drawable-xhdpi For extra high resolution screens.

Android does not decrease the quality of .bmp files when they are allocated in those folders. You have to fill each folder with the correct sized images.

About second question, I am not sure whether the android design preview screen uses the correct images or not, but in a real app running on a phone, it will.

And third question: sorry, but not.

Good luck!

Upvotes: 1

Pedro Valério
Pedro Valério

Reputation: 94

1) You don't need the different folders if you will put the same things in those folders. The designer/developer puts the resources that most adapt to that configuration.

2) You can select what kind of device you're previewing the design with (resolution and dpi), on the design tools. It will attempt to load the appropriate resource for that configuration.

3) Loading smaller images into memory may be helpful, as well as resizing them before displaying them (libraries like Picasso can do this out of the box), or you could be looking at a leak of some sort.

Upvotes: 1

Related Questions