Working with graphics is an integral part of Android application development. Without high-quality images, it is difficult to imagine a modern interface: from application icons to background illustrations and animations. However, simply dragging an image into the project folder is not enough - you need to consider screen resolutions, pixel densities, file formats and resource optimization. In this article, we will look at all the nuances of adding images to Android Studio for 2026, including new recommendations from Google on working with Vector Drawable i AVIF.

You will learn how to properly structure graphic resources, avoid common mistakes with stretching images, and why it is sometimes better to use vectors instead raster. We will also reveal optimization secrets that will speed up the loading of your application by 20-30% without loss of quality. This instruction is suitable for both beginners and experienced developers who want to systematize knowledge about working with graphics in Android.

1. Preparing images: formats and requirements

Before adding a picture to a project, it must be properly prepared. Android Studio supports several graphic file formats, but not all of them are equally effective. Main options:

  • ๐Ÿ–ผ๏ธ PNG โ€”ideal for icons and graphics with transparency (alpha channel). Supports lossless compression, but the file weight can be large.
  • ๐Ÿ“ท JPEG/JPG โ€” optimal for photographs and complex images without transparency. It compresses well, but loses quality.
  • ๐Ÿ”บ WebP โ€”recommended by Google as a universal format. Combines quality PNG and compression JPEG, supports animation.
  • ๐Ÿ”„ AVIF - a new format based on AV1, provides better compression than WebP, but not all devices support it yet.
  • ๐Ÿ“ SVG/XML โ€” vector graphics for scalable icons (converted to Vector Drawable).

For application icons (mipmap) Google recommends using PNG with a resolution of at least 512ร—512 px for mipmap-xxxhdpi. For background images it is better to choose WebP with a quality setting of 80-90%. Important: if your application supports Android 12+, check compatibility with the format AVIF - it can reduce the weight of graphics by 30-50% without visual loss.

โš ๏ธ Attention: Images with a higher resolution 4096ร—4096 px may cause an error OutOfMemoryError when loading. Always reduce the size to the required minimum.
Format Transparency Compression Recommended use
PNG โœ… Yes Lossless Icons, logos, graphics with transparency
JPEG โŒ No Lossy Photos, complex images
WebP โœ… Yes Lossless/lossy Universal format for all types of graphics
AVIF โœ… Yes With/without losses High-quality graphics (requires support verification)

Before adding images to your project, be sure to optimize them using tools like TinyPNG, Squoosh or plugin Android Image Asset Studio v Android Studio. This will reduce the size APK/AAB and speed up the loading of the application.

๐Ÿ“Š What image format do you use most often?
PNG
JPEG
WebP
SVG/Vector
AVIF

2. Folder structure for graphic resources

Images are stored in special folders inside the directory Android Studio images are stored in special folders inside the directory res. Each folder corresponds to a specific screen density (density), which allows the system to automatically select the appropriate option depending on the device. Main folders:

  • ๐Ÿ“ drawable - universal resources (vectors, XML-graphics).
  • ๐Ÿ“ drawable-ldpi (~120 dpi) - outdated, but may be required for very old devices.
  • ๐Ÿ“ drawable-mdpi (~160 dpi) - basic resolution (1x).
  • ๐Ÿ“ drawable-hdpi (~240 dpi) - 1.5x from the base.
  • ๐Ÿ“ drawable-xhdpi (~320 dpi) - 2x from the base (the most common).
  • ๐Ÿ“ drawable-xxhdpi (~480 dpi) - 3x from the base.
  • ๐Ÿ“ drawable-xxxhdpi (~640 dpi) - 4x from the base (for flagships).
  • ๐Ÿ“ mipmap-* โ€” for application icons (processed differently than drawable).

For vector images (Vector Drawable) a folder is used drawable without density prefixes. The system automatically scales vectors to fit any screen. This saves space in the project and simplifies support different resolutions.

โš ๏ธ Attention: If you add an image only to drawable-xhdpi, on devices with xxhdpi or xxxhdpi the system will scale it up, which may lead to loss of quality. Always provide options for all densities or use vectors.

Example structure for an image background.png:

res/

โ”œโ”€โ”€ drawable-xhdpi/

โ”‚ โ””โ”€โ”€ background.png (size: 640ร—480 px)

โ”œโ”€โ”€ drawable-xxhdpi/

โ”‚ โ””โ”€โ”€ background.png (size: 960ร—720 px)

โ””โ”€โ”€ drawable-xxxhdpi/

โ””โ”€โ”€ background.png (size: 1280ร—960 px)

To simplify the work, you can use the tool Android Asset Studio (built into Android Studio), which automatically generates images for all densities from one source. To open it, right-click on the folder res โ†’ New โ†’ Image Asset.

๐Ÿ’ก

If your image contains only simple shapes (circles, rectangles, lines), always convert it to Vector Drawable. This will reduce the size APK and improve quality on any screen.

3. Ways to add images to a project

There are several ways to add an image to Android Studio. The choice depends on the type of graphics and your tasks. Let's consider all the options in detail.

3.1. Manual addition via the file system

The easiest method is to copy the image files to the appropriate folders drawable or mipmap:

  1. Open your project folder in Android Studio.
  2. Go to app/src/main/res.
  3. Select the desired density folder (for example drawable-xhdpi).
  4. Drag and drop image files or copy them through Explorer.

Once added, Android Studio will automatically update the resource index. To use an image in code, refer to it by its file name (without extension):

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/your_image" />

3.2. Import via Android Asset Studio

This method is suitable for generating application icons or adaptive images:

  1. Right-click on the folder res โ†’ New โ†’ Image Asset.
  2. Select the resource type: Launcher Icons, Action Bar and Tab Icons or Notification Icons.
  3. Upload the source image (recommended size: 1024ร—1024 px for icons).
  4. Adjust settings for cropping, padding and effects.
  5. Click Next โ†’ Finish.

The tool will automatically generate images for all densities and save them in mipmap or drawable.

3.3. Adding vector images (SVG โ†’ Vector Drawable)

For vector graphics:

  1. Copy the file SVG to the project folder (for example, in app/src/main).
  2. Right click on the folder drawable โ†’ New โ†’ Vector Asset.
  3. Select Local file (SVG, PSD) and specify the path to your file.
  4. Adjust sizes and colors if necessary.
  5. Click Next โ†’ Finish.

Android Studio converts SVG to Vector Drawable (.xml), which can be used as a regular resource:

android:src="@drawable/your_vector_image"

3.4. Connecting images via URL (Glide/Picasso libraries)

If the image is stored on the network, load it dynamically using libraries:

  • ๐ŸŒ Glide - recommended by Google, supports caching and animations.
  • ๐Ÿ–ผ๏ธ Picasso - simple and easy option.
  • ๐Ÿš€ Coil - modern alternative with coroutine support.

Example with Glide:

implementation 'com.github.bumptech.glide:glide:4.16.0'

In code:

Glide.with(context)

.load("https://example.com/image.jpg")

.into(imageView);

โ˜‘๏ธ Preparing to add an image

Completed: 0 / 5

4. Optimizing images for Android

Unoptimized images are one of the main reasons for the large size APK/AAB and slow loading of the application. Here are the key optimization rules:

  • ๐Ÿ“‰ Reduce file size without loss of quality using TinyPNG, Squoosh or WebP.
  • ๐Ÿ” Use the correct permissions:
    • mdpi: 1x (basic size).
    • hdpi: 1.5x.
    • xhdpi: 2x.
    • xxhdpi: 3x.
    • xxxhdpi: 4x.
  • ๐Ÿ”„ Convert to WebP โ€”it is 25-35% lighter PNG with the same quality.
  • ๐ŸŽจ For icons, use vectors (Vector Drawable), if they do not contain complex gradients.
  • ๐Ÿ—‘๏ธ Remove unused resources via Refactor โ†’ Remove Unused Resources.

For automatic optimization, add to build.gradle plugin Android Image Compression:

plugins {

id 'com.android.application'

id 'com.tinypng' // Image compression plugin

}

Also pay attention to resConfig v build.gradle โ€”it allows you to exclude resources for unused languages or densities, reducing the size APK:

android {

defaultConfig {

resConfigs "en", "ru" // Leave only English and Russian

}

}

โš ๏ธ Attention: Images in the folder drawable-nodpi are not scaled by the system. Use this folder only if you know exactly what you are doing (for example, for 9-patch images).
๐Ÿ’ก

Optimizing images can reduce the APK size by 30-50%, which is critical for users with slow Internet or limited traffic.

5. Working with Vector Drawable and responsive icons

Vector graphics (Vector Drawable) have become the standard for icons and simple illustrations in Android. Its main advantages:

  • โœ… Scales without loss of quality on any screen.
  • โœ… Takes up less space than a raster (one file instead of 5-6 for different densities).
  • โœ… Supports animation and dynamic color changes.

To create Vector Drawable:

  1. Prepare a file in the format SVG (you can create in Adobe Illustrator, Figma or Inkscape).
  2. In Android Studio right-click on drawable โ†’ New โ†’ Vector Asset.
  3. Select Local file (SVG, PSD) and upload your file.
  4. Adjust sizes (recommended 24x24 dp for icons).
  5. Click Next โ†’ Finish.

For adaptive icons (Adaptive Iconsappeared in Android 8.0):

  1. Click right-click on res โ†’ New โ†’ Image Asset.
  2. Select Launcher Icons (Adaptive and Legacy).
  3. Upload background and foreground images (at least size 108x108 dp).
  4. Customize the mask shape (circle, rounded square, etc.).
  5. Generate icons for all densities.

Example code for dynamically changing the color of a vector image:

ImageView icon = findViewById(R.id.icon);

Drawable drawable = icon.getDrawable();

if (drawable instanceof VectorDrawableCompat) {

VectorDrawableCompat vector = (VectorDrawableCompat) drawable;

vector.setTint(ContextCompat.getColor(this, R.color.new_color));

}

To animate vectors, use AnimatedVectorDrawable:

<animated-vector

xmlns:android="http://schemas.android.com/apk/res/android"

android:drawable="@drawable/your_vector">

<target android:name="path1" android:animation="@anim/rotate"/>

</animated-vector>

How to check Vector Drawable support on the device?

Starting with Android 5.0 (API 21) Vector Drawable is supported natively For older versions, use. library appcompat-v7that provides backward compatibility through VectorDrawableCompat.

6. Common errors and their solutions

When working with images in Android Studio we will look at the most common problems and ways to fix them.

6.1. Image not showing in ImageView

Possible reasons and solutions:

  • ๐Ÿ” Invalid file name โ€” resource names must be in lowercase, without spaces and special characters (except _). data-i="230">Incorrect file name my_image.png โœ…, MyImage.png โŒ.
  • ๐Ÿ“ The file is in the wrong folder โ€”check that the image is in drawable or mipmapand not in assets.
  • ๐Ÿ”„ Android Studio cache โ€”try Build โ†’ Clean Project and Build โ†’ Rebuild Project.
  • ๐Ÿ“ฑ Unsupported format โ€” AVIF may not work on older devices. Use WebP for compatibility.

6.2. or distorted

The problem is usually associated with incorrect parameters scaleType in ImageView:

  • ๐Ÿ“ Use adjustViewBounds="true" to maintain proportions:
<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/my_image"

android:adjustViewBounds="true"

android:scaleType="centerCrop"/>

Basic values scaleType:

Value Description
matrix Uses the transformation matrix (default).
fitXY Stretches the image in width and height (may distort).
fitCenter Scales while maintaining proportions, centers.
centerCrop Scales and crops to the center.
centerInside Scales so that the image fits completely into ImageView.

6.3. OutOfMemoryError when loading large images

This error occurs when Android attempts to load an image that is too large into memory. Solutions:

  • ๐Ÿ“‰ Reduce resolution source file (for example, from 4000x3000 px to 1920x1080 px).
  • ๐Ÿ”„ Use libraries (Glide, Picasso), which automatically reduce the size:
Glide.with(context)

.load(R.drawable.large_image)

.override(800, 600) // Force size reduction

.into(imageView);

  • ๐Ÿ—‘๏ธ Load in the background using AsyncTask or Coroutines.
  • ๐Ÿ“‚ Use BitmapFactory.Options for memory-efficient decoding:
BitmapFactory.Options options = new BitmapFactory.Options();

options.inSampleSize = 4; // Reduces the size by 4 times

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.large_image, options);

6.4. The application icon is not updated on the device

Sometimes after replacing the icon in mipmap the changes are not applied. This is due to caching Android. Solutions:

  • ๐Ÿ”„ Clear the application cache in the device settings.
  • ๐Ÿ“ฑ Delete and install the application again.
  • ๐Ÿ”ง Check AndroidManifest.xml โ€”the icon must be specified correctly:
<application

android:icon="@mipmap/ic_launcher"

android:roundIcon="@mipmap/ic_launcher_round"

...>

  • ๐Ÿ“ Make sure there are icons in all folders mipmap-*.
๐Ÿ’ก

90% of problems with images in Android are solved by checking file paths, clearing the cache and correctly setting scaleType.

7. Dynamic loading and caching of images

If your application loads images from the network (for example, user avatars or product photos), you need to use libraries for caching and optimization. This will speed up loading and reduce the load on the server.

The most popular libraries:

  • ๐ŸŒŸ Glide โ€”recommended Google, supports GIF, WebPcaching in memory and on disk.
  • ๐Ÿ–ผ๏ธ Picasso โ€”simple and lightweight, but less functional than Glide.
  • ๐Ÿš€ Coil - modern library on Kotlin Coroutines, optimized for Jetpack Compose.
  • ๐Ÿ“ฆ Fresco - from Facebook, supports progressive loading JPEG.

Usage example Glide to load an image with transformations:

Glide.with(context)

.load("https://example.com/user_avatar.jpg")

.circleCrop() // Crop into a circle (for avatars)

.placeholder(R.drawable.placeholder) // Placeholder during loading

.error(R.drawable.error) // Image when error

.diskCacheStrategy(DiskCacheStrategy.ALL) // Cache all versions

.into(avatarImageView);

For manual caching (for example, for offline mode) you can use LruCache:

LruCache<String, Bitmap> memoryCache = new LruCache<String, Bitmap>(maxMemory) {

@Override

protected int sizeOf(String key, Bitmap bitmap) {

return bitmap.getByteCount();

}

};

To clear the cache Glide:

Glide.get(context).clearMemory(); // Clear memory

new Thread(() -> Glide.get(context).clearDiskCache()).start(); // Disk Cleanup

โš ๏ธ Attention: When downloading images from the network, always check the permissions in AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />

8. Advanced techniques: 9-patch, Layer List, Animated Drawable

Special types of resources are used to create complex graphic effects in Android . Let's look at the most useful of them.

8.1. 9-patch images (stretchable background images)

9-patch (NinePatch) is a special format PNG, which allows you to stretch the image without distortion. Used for background images of buttons, dialogs and other elements.

How to create 9-patch:

  1. Add an image to a folder drawable with the extension .9.png (for example, background.9.png).
  2. Open it in Android Studio โ€”you will see an interface for marking stretchable areas.
  3. Draw black lines along the edges:
    • Left and top linesโ€”define the stretchable area.
    • Right and bottomโ€”area for placing content (optional).
  • Save the file.
  • Usage example:

    <Button
    

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:background="@drawable/button_background_9patch" />

    8.2. Layer List (layered images)

    Layer List allows you to combine several images in one resource. Defined in XML:

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    

    <item>

    <bitmap android:src="@drawable/background" />

    </item>

    <item android:gravity="center">

    <bitmap android:src="@drawable/icon" />

    </item>

    </layer-list>

    Application:

    <ImageView
    

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:src="@drawable/layered_image" />

    8.3. Animated Drawable (image animation)

    For simple frame-by-frame animation, use AnimationDrawable:

    <animation-list xmlns:android="http://schemas.android.com/apk/res/android">
    

    <item android:drawable="@drawable/frame1" android:duration="100" />

    <item android:drawable="@drawable/frame2" android:duration="100" />

    <item android:drawable="@drawable/frame3" android:duration="100" />

    </animation-list>

    Running animation in code:

    ImageView animationView = findViewById(R.id.animation_view);
    

    animationView.setBackgroundResource(R.drawable.animation_list);

    AnimationDrawable animation = (AnimationDrawable) animationView.getBackground();

    animation.start();

    For complex animations, use AnimatedVectorDrawable or a library like Lottie (for