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 resolution4096ร4096 pxmay cause an errorOutOfMemoryErrorwhen 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.
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 thandrawable).
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 todrawable-xhdpi, on devices withxxhdpiorxxxhdpithe 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:
- Open your project folder in Android Studio.
- Go to
app/src/main/res. - Select the desired density folder (for example
drawable-xhdpi). - 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):
<ImageViewandroid: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:
- Right-click on the folder
resโNewโImage Asset. - Select the resource type:
Launcher Icons,Action Bar and Tab IconsorNotification Icons. - Upload the source image (recommended size:
1024ร1024 pxfor icons). - Adjust settings for cropping, padding and effects.
- 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:
- Copy the file SVG to the project folder (for example, in
app/src/main). - Right click on the folder
drawableโNewโVector Asset. - Select
Local file (SVG, PSD)and specify the path to your file. - Adjust sizes and colors if necessary.
- 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
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 folderdrawable-nodpiare not scaled by the system. Use this folder only if you know exactly what you are doing (for example, for9-patchimages).
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:
- Prepare a file in the format SVG (you can create in Adobe Illustrator, Figma or Inkscape).
- In Android Studio right-click on
drawableโNewโVector Asset. - Select
Local file (SVG, PSD)and upload your file. - Adjust sizes (recommended
24x24 dpfor icons). - Click
NextโFinish.
For adaptive icons (Adaptive Iconsappeared in Android 8.0):
- Click right-click on
resโNewโImage Asset. - Select
Launcher Icons (Adaptive and Legacy). - Upload background and foreground images (at least size
108x108 dp). - Customize the mask shape (circle, rounded square, etc.).
- 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-vectorxmlns: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 namemy_image.pngโ ,MyImage.pngโ. - ๐ The file is in the wrong folder โcheck that the image is in
drawableormipmapand not inassets. - ๐ Android Studio cache โtry
Build โ Clean ProjectandBuild โ 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:
<ImageViewandroid: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 pxto1920x1080 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
AsyncTaskorCoroutines. - ๐ Use
BitmapFactory.Optionsfor 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:
<applicationandroid: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:
- Add an image to a folder
drawablewith the extension.9.png(for example,background.9.png). - Open it in Android Studio โyou will see an interface for marking stretchable areas.
- Draw black lines along the edges:
- Left and top linesโdefine the stretchable area.
- Right and bottomโarea for placing content (optional).
Usage example:
<Buttonandroid: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:
<ImageViewandroid: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